Scoping issues
text = ['aaaa', 'bb', 'ccc ccc']
length_1 = [ len(s) for s in text ]
print(length_1) # [4, 2, 7]
length_2 = [ len(s) for x in text ]
print(length_2) # [7, 7, 7]
List comprehensions don't create their own scope!
Press ← or → to navigate between chapters
Press S or / to search in the book
Press ? to show this help
Press Esc to hide this help
text = ['aaaa', 'bb', 'ccc ccc']
length_1 = [ len(s) for s in text ]
print(length_1) # [4, 2, 7]
length_2 = [ len(s) for x in text ]
print(length_2) # [7, 7, 7]
List comprehensions don't create their own scope!