-
Notifications
You must be signed in to change notification settings - Fork 176
Expand file tree
/
Copy pathcomprehension1.py
More file actions
67 lines (38 loc) · 1.62 KB
/
comprehension1.py
File metadata and controls
67 lines (38 loc) · 1.62 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
# List Comprehension
fruits = [f for f in fruit_list if f.startswith("a")]
fruit_list = [fruit for fruit in fruits]
sum_cord = [x + y for (x, y) in points if x > 0 and y > 0]
transform_1 = [2*x + 6 for x in range(10)]
distance_orig = [x**2 + y**2 + z**2 for x, y, z in points]
odd_elements = [i for i in main_list if i & 1]
first_ten_elements = [i for (i) in range(10)]
another_ten_elements = [(i) for (i) in range(10)]
comp = [i**2 for i in range(10) if i not in [3, 5, 7] and i in list3]
items = [
name
for name, value in vars(argparse).items()
if not (name.startswith("_") or name == 'ngettext')
if not inspect.ismodule(value)
]
[0 async for tgt[0] in source()]
# Generator Expression
prm_tup = tuple(next(parameters) for _ in i.__parameters__)
args = ", ".join(_to_str(i) for i in self.__args__)
rest = tuple(i for i in range(a.ndim) if i not in axis)
(sstr(x) for [x] in self._module.gens)
func(*[[x*y] for [x] in self._module.gens for [y] in J._module.gens])
(x for [a, b] in y)
(x for [a, (b, c)] in y)
(x for [(b, c)] in y)
(x for [] in y)
(string[i] for i in range(len(string)-1, -1, -1))
k = (j + k for j, k in range(10) if j > 0)
(left + size + right for size, (left, right) in zip(array.shape, pad_width))
viter = ((i, j) for ((i, _), (j, _)) in zip(newargs[1:], args[1:]))
# Set Comprehension
newSet = {element*3 for element in myList}
newSet = {element*3 for element in myList if element % 2 ==0}
# Dictionary Comprehension
{x: x**3 for x in range(10) if x**3 % 4 == 0}
square_dict = {num: num*num for num in range(1, 11)}
error_names = [test_full_name.split(" ")[0] for (test_full_name, *_) in errors]