Ad
Strings
Data Types

lambda functions!
Also it's bad practice to use reserved words as parameters.

Code
Diff
  • last_char = lambda s: s[-1]
    • def last_char(str):
    • return str[-1]
    • last_char = lambda s: s[-1]

math.sqrt(n) = n**.5

although that may lead unreadable code.

for python 3 replace long(...) with int(...)

Code
Diff
  • fib = lambda n: long((((1+5**.5)/2)**(n+1) - ((1-5**.5)/2)**(n+1))/5**.5)
    • import math
    • def fib(n):
    • return long((((1+math.sqrt(5))/2)**(n+1) - ((1-math.sqrt(5))/2)**(n+1))/math.sqrt(5))
    • fib = lambda n: long((((1+5**.5)/2)**(n+1) - ((1-5**.5)/2)**(n+1))/5**.5)