Skip to content

Commit 2f7b59c

Browse files
Kevin LuKevin Lu
Kevin Lu
authored and
Kevin Lu
committed
updates
1 parent c796c8b commit 2f7b59c

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

.pytest_cache/v/cache/nodeids

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

.pytest_cache/v/cache/stepwise

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

Lesson 4/itertools.py

+41-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,45 @@
11
# demonstration of commonly used tools in itertools
2+
# commonly used ones from https://docs.python.org/2/library/itertools.html#module-itertools
3+
# do not memorize them but just remember they exist when you practice
4+
#
5+
26
from itertools import *
7+
8+
# for repetition
9+
10+
# count
311
for i in count():
4-
print(i)
12+
if i == 10:
13+
break
14+
print(i)
15+
16+
# cycle
17+
n = 0
18+
for i in cycle('ABCD'):
19+
print(i)
20+
n += 1
21+
if n > 8:
22+
break
23+
24+
# repeat
25+
for i in repeat('X', 3):
26+
print(i)
27+
28+
# combinatorical functions
29+
30+
# fun fact: the reason it is called a product is since this is precisely what you would arrive
31+
# at if you expanded (A + B + C)(X + Y + Z)
32+
print(list(product('ABC', 'XYZ')))
33+
34+
print(list(permutations('ABCD', 2)))
35+
36+
print(list(combinations('ABCD', 2)))
37+
38+
# for iterators
39+
40+
print(list(starmap(lambda a, b: a > b, [(1,2), (4,5), (10, 1)])))
41+
42+
# HW #1: find out what tee() does from https://docs.python.org/3/library/itertools.html#itertools.tee
543

44+
# functools: https://docs.python.org/3/library/functools.html
45+
# operators: https://docs.python.org/3/library/operator.html

0 commit comments

Comments
 (0)