0
\$\begingroup\$

I was wondering if it was possible to make this code even shorter than it already was.

f=lambda x:f(x-1)+f(x-2) if x>1 else 1
[print(f(i))for i in range(20)]

Expected output:

1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765

Good luck, "golfers" (I'm assuming thats what you guys are called)

Note: specifically in Python 3 Note2: By shortest I mean taking up the least characters

\$\endgroup\$
1
  • \$\begingroup\$ On https://code.golf/fibonacci#python (printing the first 30 starting with 0), the best Python 3 answers are 36 bytes, so there's quite a bit of room for golfing. for a starting point, take a look at our Python golf tips. \$\endgroup\$
    – xnor
    Jan 5 at 23:38

0

Browse other questions tagged or ask your own question.