Repository navigation
Expand file tree
/
Copy pathsamplefile.py
More file actions
98 lines (84 loc) · 2.03 KB
/
Copy pathsamplefile.py
File metadata and controls
98 lines (84 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import itertools
import operator
letters = ['a', 'b', 'c', 'd']
numbers = [1, 2, 3, 2, 1, 0]
names = ['Corey', 'Nicole']
selectors = [True, True, False, True]
def lt_2(num):
if num < 2:
return True
return False
def get_state(person):
return person['state']
people = [
{
'name': 'John Doe',
'city': 'Gotham',
'state': 'NY'
},
{
'name': 'Jane Doe',
'city': 'Kings Landing',
'state': 'NY'
},
{
'name': 'Corey Schafer',
'city': 'Boulder',
'state': 'CO'
},
{
'name': 'Al Einstein',
'city': 'Denver',
'state': 'CO'
},
{
'name': 'John Henry',
'city': 'Hinton',
'state': 'WV'
},
{
'name': 'Randy Moss',
'city': 'Rand',
'state': 'WV'
},
{
'name': 'Nicole K',
'city': 'Asheville',
'state': 'NC'
},
{
'name': 'Jim Doe',
'city': 'Charlotte',
'state': 'NC'
},
{
'name': 'Jane Taylor',
'city': 'Faketown',
'state': 'NC'
}
]
# result = itertools.combinations(numbers, 3)
# result = itertools.permutations(numbers, 3)
# result = itertools.product(numbers, repeat=4)
# result = itertools.combinations_with_replacement(numbers, 4)
# result = itertools.islice(range(5), 1, 5, 2)
# combined = itertools.chain(letters, numbers, names)
# result = itertools.compress(letters, selectors)
# result = filter(lt_2, numbers)
# result = itertools.filterfalse(lt_2, numbers)
# result = itertools.dropwhile(lt_2, numbers)
# result = itertools.takewhile(lt_2, numbers)
# result = itertools.accumulate(numbers)
# result = itertools.accumulate(numbers, operator.mul)
# for item in result:
# print(item)
person_group = itertools.groupby(people, get_state)
for key, group in person_group:
print(key)
for person in group:
print(person)
print()
# with open('test.log', 'r') as f:
# header = itertools.islice(f, 3)
# for line in header:
# print(line, end='')