Python Forum
Calculating frequency of items in a dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calculating frequency of items in a dictionary
#2
You can use dict.setdefault method, e.g.

desired_output = dict()                                                                                                                                                                                                                                                       
for item in input_dict: 
    ss = sum(v for k, v in input_dict[item].items()) 
    tt = desired_output.setdefault(ss, list()) 
    tt.append(item) 
Reply


Messages In This Thread
RE: Calculating frequency of items in a dictionary - by scidam - Nov-27-2019, 04:21 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how to assign items from a list to a dictionary CompleteNewb 3 1,639 Mar-19-2022, 01:25 AM
Last Post: deanhystad
  finding items/comparison in/with a dictionary AGC 17 7,333 Apr-02-2018, 08:30 PM
Last Post: AGC
  Python find the minimum length of string to differentiate dictionary items zydjohn 3 3,680 Mar-03-2018, 05:23 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020