PROGRAMMING

m9/ PYTHON
REMEMBERS




List

p329 ! For loops can be write more concisely using list comprehension.
 
str = "abc"

res = []
for s in str:
    res.append(s.capitalize())

print(res) # ['A', 'B', 'C']
 
# The loop variable appears in expression before we get to definition
# LIst comprehensions are harder to debug

str = "abc"
res = [s.capitalize() for s in str]

print(res) # ['A', 'B', 'C']

Questions    
Generator

        A B C D E F
🔔
1/1