Dec-25-2021, 02:49 AM
(This post was last modified: Dec-25-2021, 02:49 AM by BashBedlam.)
You just have
return Counter(final_list)
indented one tab too far. It's returning after just one iteration through the loop.from collections import Counter buckets = [ ('[email protected]',{'first_name':'john','last_name':'doe'}), ('[email protected]',{'first_name':'jane','last_name':'doe'}), ('[email protected]',{'first_name':'derek','last_name':'zoolander'}), ('[email protected]',{'first_name':'murph','last_name':'cooper'}), ('[email protected]',{'first_name':'ned','last_name':'stark'}) ] def get_last_name_count(list_of_records): final_list = [] for key, value in list_of_records: last_names = value['last_name'] final_list.append(last_names) return Counter(final_list) result = get_last_name_count(buckets) for k, v in result.items(): print(f"{k}: {v}")
Output:doe: 2
zoolander: 1
cooper: 1
stark: 1