In advanced collections module in python 2.7. What is the difference between Counter(dict(c.items)) and dict(c) -


//this code  sen = 'how many times each word show in sentence word word shows up shows'  words = sen.split()  c = counter(words)  dict(c)  counter(dict(c.items())) 

//output

//output of dict(c)  {'how': 1,  'does': 1,  'each': 1,  'in': 1,  'many': 1,  'sentence': 1,  'show': 1,  'shows': 2,  'the': 1,  'times': 1,  'up': 3,  'word': 3}   //output of counter(dict(c.items()))  counter({'how': 1,          'does': 1,          'each': 1,          'in': 1,          'many': 1,          'sentence': 1,          'show': 1,          'shows': 2,          'the': 1,          'times': 1,          'up': 3,          'word': 3}) 

read docs counters. they're used tallying only. provides other operations aren't available vanilla dict's.


Comments