-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcursed.py
More file actions
55 lines (50 loc) · 1.28 KB
/
cursed.py
File metadata and controls
55 lines (50 loc) · 1.28 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
# Multiple expressions in one lambda
(
lambda _=None: (
print("I"),
print("love"),
print("Python!")
)
)()
# Assign variables in lambda
(
lambda _=None: (
# globals is a dictionary that holds all global variables in script
# .update replaces '='
# {} anonymous dictionary where key is the variable's name and value is the variable's value
globals().update({"num": 1}),
print(num),
)
)()
# If statement in lambda
(
lambda _=None: (
globals().update({"number": 0}),
number == 0 and print("number is 0"),
globals().update({"number": 14}),
number == 0 and print("number is 0") or number == 7 and print("number is 7") or print("number is not 0 or 7")
)
)()
# For loop in lambda
(
lambda _=None: (
# for i in range(10):
# print(i)
[(lambda x: (
print(x)
))(i) for i in range(10)]
)
)()
# While loop in lambda (recursion)
(lambda _=None: (
globals().update({"count": 0}),
globals().update({"func": (lambda _=None: (
# count += 1
globals().update({"count": globals().get("count") + 1}),
print(count),
# if count < 10:
# func()
count < 10 and func()
))}),
func()
))()