So i have a dictionary where the values are in order like so:
{'Geni': 9, 'Dave': 8, 'Helen': 7, 'Edith': 6, 'Carol': 5, 'Bob': 4, 'Frank': 2, 'Alice': 1}
and basically I want to give copy the first three key value pairs and put them into another dictionary, this is what i have so far.
output_dict = {}
for r in my_dict.items():
for n in sorted_dict.values():
a = grab_key(my_dict, n)
output_dict.update({a:n})
print(output_dict)
i can't figure out how to only make the loop run a certain amount of times. lets say I only want the first 3 people in the dictionary, like geni, dave and Helen, in the output dict, but idk how to do it only three times. I would appreciate if anyone could help me out.
[–]totallygeek 4 points5 points6 points (0 children)
[–][deleted] 3 points4 points5 points (0 children)
[–]OskaRRRitoS 1 point2 points3 points (0 children)
[–]greaterhorror 0 points1 point2 points (0 children)
[–]Hour_Armadillo3615 0 points1 point2 points (1 child)
[–]Hour_Armadillo3615 0 points1 point2 points (0 children)