I want to do a random.choice() but the same sample can only be selected a maximum of 2 times?
import collections
import numpy as np
l_ev=[]
list_items=['aa', 'bb', 'cc','dd', 'ee']
num=3
for i in range(3):
l_objects_draw = np.random.choice(list_items, num)
print('draw: '+str(l_objects_draw))
l_ev.extend(l_objects_draw)
print('l_ev' + str(l_ev))
dup = [item for item, count in collections.Counter(l_ev).items() if count > 1]
print('dup: ' + str(dup))
list= [x for x in list_items if x not in dup]
print('new list' + str(list_items))
should randomly select from list but cannot return any item from the list more than more than 2 times for example.
Currently, if 'aa' is selected in the first iteration of the for loop, it is not removed from the list since it is only selected once. it could be that in the second iteration of the loop, 'aa' is selected twice eg and then only removed from the list.
This would mean that l_ev may contain 3 'aa' elements. I want to avoid this. but preserve the number of items selected in each iteration ie 'num' hence I simply can not remove it.