-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10.function.py
More file actions
53 lines (42 loc) · 1.17 KB
/
Copy path10.function.py
File metadata and controls
53 lines (42 loc) · 1.17 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
# Theory of FUNCTIONS
# FUNCTION BUILT-IN
# random
import random
a = [1,2,3,4]
print(random.choice(a))
print(random.sample(a,2))
# itertool
import itertools as it
#cycle
for index, item in enumerate(it.cycle(a)):
print(index, item, "Edmar")
if index >= 10:
break
b = it.repeat(a,4)
print(list(b))
# output > [[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]]
# accumulate > Return series of accumulated sums (or other binary function results).
c = it.accumulate(a)
print(list(c))
#output > [1, 3, 6, 10]
print(it.accumulate.__doc__)
# PERMUTATIONS
"""
Return successive r-length permutations of elements in the iterable.
permutations(range(3), 2) --> (0,1), (0,2), (1,0), (1,2), (2,0), (2,1)
"""
d = it.permutations("ABC", 2)
print(list(d))
print(d.__doc__)
# output > [('A', 'B'), ('A', 'C'), ('B', 'A'), ('B', 'C'), ('C', 'A'), ('C', 'B')]
# COMBINATION
"""
Return successive r-length combinations of elements in the iterable.
combinations(range(4), 3) --> (0,1,2), (0,1,3), (0,2,3), (1,2,3)
"""
e = it.combinations("ABC", 2)
print(list(e))
print(e.__doc__)
#output > [('A', 'B'), ('A', 'C'), ('B', 'C')]
import functools as ft
# It is used to moniterate function