REMEMBER PYTHON

MINTE9
2REMEMBER




List

p329 ! For loops can be write more concisely using list comprehension. The loop variable appears in expression before we get to definition. LIst comprehensions are harder to debug, use them only in simple cases.
 RunCode
str = "abc"

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

print(res) # ['A', 'B', 'C']
... 5 lines
˄˄˄
 RunCode
str = "abc"

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

print(res) # ['A', 'B', 'C']
... 3 lines
˄˄˄

Questions    
No. 31   Generator
CARD
30
32

        A B C D E F
🔔
1/1