I have a dictionary with empty values. I would like the values of the dictionary to be lists with 2 random items from another list of attributes but if the first random attribute is either attribute1 or attribute2 then the second random attribute can't be attribute1 or attribute2 again. Also in general it the 2 attributes in the list can't be the same. This is what I have right now:
import random
elem_list = ['Elem1', 'Elem2', 'Elem3']
dict_1 = dict.fromkeys(elem_list)
attributes = ['attribute1', 'attribute2', 'attribute3', 'attribute4']
attributes2= ['attribute3', 'attribute4']
#First elem in value list for dictionary is random
for elem in dict_1:
dict_1[elem] = [random.choice(attributes)]
#2nd is dependent
for elem in dict_1:
if dict_1[elem] == 'attribute1' or 'attribute2':
for elem in dict_1[elem]:
elem.append(random.choice(attributes2))
print(dict_1)
So in the end dict_1 should look something like this:
dict_1 = {
'Elem1': ['attribute1', 'attribute3'],
'Elem2': ['attribute2', 'attribute4'],
'Elem3': ['attribute3', 'attribute4'
}