Python Forum
What is the best way to add entries from 1 dictionary to another?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is the best way to add entries from 1 dictionary to another?
#1
I have a dictionary:

Quote:rev_sorted_dataDict = dict(sorted(dataDict.items(), reverse = True, key=lambda item: item[1][3]))

The dictionary rev_sorted_dataDict has a student number as key and the value is a list of: [student number, name, class, score] and is sorted according to the score part of the list. The highest score comes first.

groupA, groupB and groupC are empty dictionaries. There are 112 students in all

I need to add the first 37 entries of rev_sorted_dataDict to groupA, the second 37 entries of rev_sorted_dataDict to groupB and the rest (38 students) to groupC.

After that, I will write groupA, groupB and groupC to excel with openpyxl.

With a list I could just append the first 37, but I don't think I can append to a dictionary

What is the best way to populate the dictionaries groupA, groupB and groupC??
Reply


Messages In This Thread
What is the best way to add entries from 1 dictionary to another? - by Pedroski55 - Oct-20-2020, 07:47 AM

Forum Jump:

User Panel Messages

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