0

I have dictionary data like the following:

dict = { 
'a' : ('12','3','12'), 
'b' : ('32','121'), 
'c' : ('232','9','11'), 
'd' : ('32'), 
'e' : ('243','232') 
}

Is that possible to count number of values for each keys?
if i use

sum(len(v) for v in dict[j].itervalues()) 

it returns counts of all values ...in above case it return 11
but i need for specific key... for example for key 'c' gives 3 (number of values it has).
so is there any a method to do it... thanks alot!

Jojo
  • 912
  • 1
  • 7
  • 8

1 Answers1

0
new_dict = {k: len(v) for k,v in dict.items()}
asafm
  • 911
  • 6
  • 17