#Python - How does this even work

9 messages · Page 1 of 1 (latest)

orchid crane
#

!exec

shadow fjordBOT
# orchid crane !exec

@orchid crane

✅ Exec - Success (Super User 🦸)
<
g
e
n
e
r
a
t
o
r
 
o
b
j
e
.
.
Removed 36 lines
.
.
 
0
x
7
f
0
3
9
e
e
1
0
3
c
0
>

orchid crane
#

wtf

sleek monolith
#

The generator is lazy, so it's never actually running the code, you'll get an error saying dictionaries aren't callable as soon as you try to iterate the generator.

orchid crane
#

Oh that does make sense

sleek monolith
#

!exec ```py
mapping = {
'1': 'I',
'2': 'Z',
'3': 'Z',
'4': 'H',
'5': 'S',
'6': 'G',
'7': 'L',
'8': 'B',
'9': '-',
'0': 'O'
}

def turn_calc(numbers: int) -> str: # broken
return next(mapping(n) for n in str(numbers))

for i in turn_calc(7284):
print(i)

shadow fjordBOT
sleek monolith
#

This is the same as a function. You don't get error messages until you run it

#

Python doesn't do type checking. If you ran it through mypy it'd give you a type error