I have a dictionary object say
d = {
'25478329': ['17647430', '376088951', '32416061', '43096205'],
'43096205': '17647430',
'376088951': ['17647430', '25478329', '32416061'],
'32416061': ['17647430', '25478329']
}
What I want is to find out the value that has occurred maximum number of times for all keys, e.g. in the above dictionary the answer will be '17647430'.
What I did is:
def di(d):
a = []
for i in d.values():
if isinstance(i,str):
a.append(i)
else:
for j in i:
a.append(j)
print a
most_common,num_most_common = Counter(a).most_common(1)[0]
print most_common,num_most_common
Can the above code be optimized?