forked from pratyushmp/code_opensource_2020
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_comprehension.py
More file actions
30 lines (21 loc) · 796 Bytes
/
Copy pathlist_comprehension.py
File metadata and controls
30 lines (21 loc) · 796 Bytes
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
def main():
numbers_up_to_100 = [x for x in range(1, 101)]
print("All of the numbers up to 100:")
print(numbers_up_to_100)
print()
odd_numbers = [x for x in numbers_up_to_100 if x % 2 == 1]
print("All of the odd numbers up to 100:")
print(odd_numbers)
print()
even_numbers = [x for x in numbers_up_to_100 if x not in odd_numbers]
print("All of the even numbers up to 100:")
print(even_numbers)
even_squares = [x ** 2 for x in even_numbers]
print("All of the even numbers up to 100 squared:")
print(even_squares)
print()
numbers_dict = {x: y for x, y in zip(odd_numbers, even_numbers)}
print("It works also with dictionaries!")
print(numbers_dict)
if __name__ == '__main__':
main()