adding iteration code examples

This commit is contained in:
muassif
2021-07-25 22:11:07 +04:00
committed by GitHub
parent 7b9db1b3fc
commit 2370a895dd
10 changed files with 97 additions and 0 deletions
+9
View File
@@ -0,0 +1,9 @@
#itertools_groupby.py
import itertools
mylist = [("A", 100), ("A", 200), ("B", 30), ("B", 10)]
def get_key(group):
return group[0]
for key, grp in itertools.groupby(mylist, get_key):
print(key + "-->", list(grp))