Python: build dictionary from list -


for assignment have build dictionary keys elements list , values list positions each element, example:

x = [13, 15, 27, 11, 13, 27]  > dict = {13:[0,4], 15:[1], 27:[2,5], 11:[3]} 

i can't positions repeated element in list.

from collections import defaultdict d = defaultdict(list) i,j in enumerate(x):     d[j].append(i) 

using defaultdict default being empty list , enumerate provide index


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -