Python列表解析式和lambda
List Comprehensions And Lambda
列表解析式 [ ] >>> print([i for i in range(10)]) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> print([i for i in range(10) if i%2]) [1, 3, 5, 7, 9] >>> print([i for i in range(10) if i%2 == 1]) [1, 3, 5, 7, 9] >>> print([i for i in range(1,10,2)]) [1, 3, 5, 7, 9] >>> print([i for i in range(20) if i%2==0
Posted by BlueFat on Sunday, August 14, 2022