Created
October 13, 2017 12:53
-
-
Save monk1337/d79aba7434df8586d7e4a34615f1603b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a=[(2010,2),(2009,4),(1989,8),(2009,7)] | |
new_dict={} | |
for i in a: | |
if i[0] not in new_dict: | |
new_dict[i[0]]=[i[1]] | |
else: | |
try: | |
new_dict[i[0]].append(i[1]) | |
except KeyError: | |
pass | |
print(new_dict) | |
#output | |
{2009: [4, 7], 2010: [2], 1989: [8]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment