-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathiterator_stuff.py
More file actions
112 lines (89 loc) · 1.75 KB
/
iterator_stuff.py
File metadata and controls
112 lines (89 loc) · 1.75 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# using the itertool
##tup = (1 ,2, 3, 4)
##my_it = iter(tup)
##
##print(my_it.__next__())
##print(my_it.__next__())
##print(my_it.__next__())
##print(my_it.__next__())
###print(my_it.__next__()) # no more
##
### plain old for loop:
##tup = (1 ,2, 3, 4)
##for item in tup:
## print(item)
# list comprehension
##list1 = [1,2,3,4]
##
##mult_list = [i * 4 for i in list1]
##print(mult_list)
# generator expression
list1 = [1,2,3,4]
mult_gen = (i * 4 for i in list1)
##print(type(mult_gen))
##print(next(mult_gen))
##print(next(mult_gen))
##print(next(mult_gen))
##print(next(mult_gen))
#
##for x in mult_gen:
## print(x)
##
###Generator function
##def one_simple_generator():
## yield "Happy"
## yield "Joyous"
## yield "Free"
##
##for x in one_simple_generator():
## print(x)
# with a filter
##secret = [10,20,30,40,50]
##def secret_numbers(x):
## if (x in secret):
## return x
## else:
## return
##
##my_list = [10,15,20,25,30,35,40]
##x = list(filter(secret_numbers, my_list))
##print(x)
# map() function
##def add_me(val):
## return val + 100
##
##numbers = (1,2,3)
##map_it = map(add_me, numbers)
##print(set(map_it))
# enumerate() function
##
##yo = ("Yo", "yo there", "yo buddy", "yo yo yo")
##
##for y in enumerate(yo, 1):
## print(y)
# sorted() function
##my_list1 = ["fish", "monkeys", "zebras", "horses", "camels"]
##
##sort_me =sorted(my_list1, reverse = True)
##print(sort_me)
# any()
##
##my_list = [False, 0, 1, ]
##my_list2 = [False, 0, None, ]
##
##print(any(my_list))
##print(any(my_list2))
##
##
### all()
##
##my_list = [False, 0, 1, ]
##my_list3 = ["Yes", 1, "time", ]
##
##print(all(my_list))
##print(all(my_list3))
# zip()
L1 = [1,2,3,4,5,6]
L2 = [2,3,4,5,6,7]
me_new= dict(zip(L1,L2))
print(me_new)