From 1f91a759d8a70a2375ba348f2475bee8b1bd6c87 Mon Sep 17 00:00:00 2001 From: Sreejith K Date: Sun, 23 Feb 2014 15:23:21 +0530 Subject: [PATCH] * Make the fibonacci solution more pythonic --- readme.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/readme.md b/readme.md index 85d53e1..5efe063 100644 --- a/readme.md +++ b/readme.md @@ -97,10 +97,7 @@ end ```python def fib(n): - if n < 2: - return n - else: - return fib(n-1) + fib(n-2) + return n if n < 2 else fib(n-1) + fib(n-2) ``` Although you can write this code in many ways, both of these methods are *true* to the language. In other words, the Ruby example is very Ruby-ish while the Python example is very Pythonic. Can you read the Ruby code? It may be more elegant but it's a bit harder to read. Meanwhile, it's easy to follow the Python code, right? You of course can write code anyway you want. It's advisable to write Ruby code, when beginning, in a more Pythonic way - which simply means making it more readable: