2 ms·
In Python: [x+1 for x in range(100)] is not a loop but it prints out the numbers 1 to 100 map(lambda x: x+1, range(100)) is also Python and more legible to some
by memracom 13y ago
In Python:
[x+1 for x in range(100)]
is not a loop but it prints out the numbers 1 to 100
map(lambda x: x+1, range(100))
is also Python and more legible to some people but the former is more idiomatic.
The key to fizzbuzz is to make the decision for a number x, whether to map it to itself or fizz or buzz or fizzbuzz. Given a function which does thatm, just map it over whatever list of integers you want. Still no loop.
Modern functional programming style does not generally write loops; that job is left to the compiler. Python does allow one to write loops, but it is fairly well known that doing so causes your code to run slower because you are fighting against the compiler and the underlying VM.