0

Consider my code:

dic={'a':[1,2,3],'b':[10,1,2],'c':[20,1,2],'d':[4,3,2,1],'e':[5,1],'f':[90,8,2]}
for x in dic:
    print ("sum of key " + str(x) + "  " + str(sum(dic[x])))
    print ("length = " + str(len(dic[x])))

now I am getting this output

sum of key a  6
length = 3
sum of key c  23
length = 3
sum of key b  13
length = 3
sum of key e  6
length = 2
sum of key d  10
length = 4
sum of key f  100
length = 3
Cory Kramer
  • 114,268
  • 16
  • 167
  • 218

1 Answers1

0

Dictionary is an unordered data structure, and that's why you get that output.

I suggest you use an array of object

{key,  array[]} 
Zimm1
  • 433
  • 5
  • 16