3 hidden Python tips 🐍
Hidden from beginner tutorials and seldom found in books.
1. You can multiply a string to repeated it:
>>> "HOOLI-"*2
'HOOLI-HOOLI-'
2. Chaining comparison operators:
>>> f = 2
>>> 1 < f < 3
True
>>> 1 < f < 3 < (f+2)
True
3. Flatten lists with sum():
>>> a = [[1,2,3], [4,5,6], [7,8,9]]
>>> sum(a, [])
[1, 2, 3, 4, 5, 6, 7, 8, 9]