Skip to content Skip to sidebar Skip to footer

Make Dictionary From 2D Array Python?

I have a 2D array as follows. [['FE0456143', '218.04'], ['FB1357448', '217.52'], ['FB1482960', '222.70'], ['FB1483107', '223.32'], ['FE0456556', '12429.67'], ['FE0456594', '213.71

Solution 1:

Sounds like you want a 1 to many mapping. You can have this if you make your value a list:

from collections import defaultdict

d = defaultdict(list)

for k, v in data:
    d[k].append(v)

Post a Comment for "Make Dictionary From 2D Array Python?"