My Favorite Pieces of Syntax in 8 Different Programming Languages
medium.com
medium.com
def even_numbers(limit):
return [num for num in range(0, limit, 2)]
It’s unfortunate they chose this specific example because it doesn’t really show the power of list comprehensions. This example could be written as return list(range(0, limit, 2))
Or even simply return range(0, limit, 2)
If one doesn’t need a mutable list.def squares(limit): return [num*num for num in range(0, limit)]
If you have another suggestion I'd be happy to hear it!