-
Notifications
You must be signed in to change notification settings - Fork 0
/
Itertools_examples_1.py
81 lines (60 loc) · 1.63 KB
/
Itertools_examples_1.py
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
#Itertools
import itertools
# counter = itertools.count(start=5, step=5)
# print(next(counter))
# print(next(counter))
# print(next(counter))
# print(next(counter))
# counter = itertools.cycle([1,2,3])
# print(next(counter))
# print(next(counter))
# print(next(counter))
# print(next(counter))
# print(next(counter))
# print(next(counter))
# print(next(counter))
# counter = itertools.cycle(('ON','OFF'))
# print(next(counter))
# print(next(counter))
# print(next(counter))
# print(next(counter))
# print(next(counter))
# print(next(counter))
# print(next(counter))
# counter = itertools.repeat(2,times=5)
# for i in counter:
# print(counter)
# data = [100, 200, 300, 400]
# dayly_data = list(itertools.zip_longest(range(10),data))
# data = [100, 200, 300, 400]
# dayly_data = list(zip(range(10),data))
# print(dayly_data)
# print(dayly_data[0])
# def hola(x):
# return x*x
# squares = list(map(hola,range(10)))
# print(squares)
# squares = itertools.starmap(pow,[(0,1),(2,3),(4,5),(6,7)])
# print(list(squares))
letters = ['a','b','c','d','e']
numbers = [2,3,4,5]
names = ['Victor','Landaeta','Jimenez']
# result = itertools.combinations(letters,3)
# for item in result:
# print(item)
result2 = itertools.combinations(numbers,2)
for item in result2:
print(item)
# result = itertools.permutations(letters,5)
# for item in result:
# print(item)
# result = itertools.permutations(numbers,4)
# for item1 in result:
# for valor in range(1,len(item1)):
# array1 = item1[:valor]
# array2 = item1[valor:]
# suma = abs(sum(array1)-sum(array2))
# print(suma)
# result = itertools.product(numbers, repeat=3)
# for item in result:
# print(item)