Created
January 25, 2018 13:23
-
-
Save fereria/c7b231bd5a67a3b80871cf1e186f8d26 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
# -*- coding: utf-8 -*- | |
from collections import defaultdict | |
src = [('a',1),('b',2),('c',3),('a',3)] | |
# 使わないとき | |
d = defaultdict(list) | |
result = {} | |
for i,j in src: | |
if i in result: | |
result[i].append(j) | |
else: | |
result[i] = [j] | |
print result | |
# defaultdict | |
for i,j in src: | |
d[i].append(j) | |
print d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment