Created
April 17, 2018 00:48
-
-
Save Everfighting/4cc35b47a6cd308082983944a733dffa to your computer and use it in GitHub Desktop.
defaultdict用法
This file contains hidden or 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
| # defaultdict Examples | |
| # Using list as the default_factory, it is easy to group a sequence of key-value pairs into a dictionary of lists: | |
| s = [('yellow', 1), ('blue', 2), ('yellow', 3), ('blue', 4), ('red', 1)] | |
| d = defaultdict(list) | |
| for k, v in s: | |
| d[k].append(v) | |
| sorted(d.items()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment