I have two list:
lists = [\'a\',\'b\',\'c\',\'d\',\'e\']
keys = [18,18,3,4,5]
what I want is a dictionary like this:
{18:[\'a\',\'
You can try this:
output = {}
for index, key in enumerate(keys):
if not key in output:
output[key] = lists[index]
else:
cur_val = output[key]
if type(cur_val) == str:
cur_val = [cur_val]
cur_val.append(lists[index])
output[key] = cur_val
print(output)
output:
{18: ['a', 'b'], 3: 'c', 4: 'd', 5: 'e'}