Oct-20-2020, 07:47 AM
I have a dictionary:
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??
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??