Browse Source

Class

pull/3/head
Jure Šorn 5 years ago
parent
commit
e47fbf17d0
1 changed files with 3 additions and 3 deletions
  1. 6
      README.md

6
README.md

@ -910,9 +910,9 @@ from itertools import *
>>> people = [{'id': 1, 'name': 'bob'},
{'id': 2, 'name': 'bob'},
{'id': 3, 'name': 'peter'}]
>>> {k: list(v) for k, v in groupby(people, key=lambda x: x['name'])}
{'bob': [{'id': 1, 'name': 'bob'},
{'id': 2, 'name': 'bob'}],
>>> {name: list(ppp) for name, ppp in groupby(people, key=lambda p: p['name'])}
{'bob': [{'id': 1, 'name': 'bob'},
{'id': 2, 'name': 'bob'}],
'peter': [{'id': 3, 'name': 'peter'}]}
```

Loading…
Cancel
Save