Python OneLiners

What use is a faster algorithm, if it isn’t a tweet size ! Sun Tzu1

Learn More

Topics to cover

  • List compression
  • Generator and Iterators
  • Lambda Functions

Code Golf Resources to devour

Writing OneLiners

Merge Multiple conditionals


if(a<b and b<c) -> if(a<b<c)

Control Statements

if expression1:
   statement1
elif expression2:
   statement2
else:
   statement3
   
statement1 if expression1 else (statement2 if expression2 else statement3)

Quick Small Random Number


# using id() on object and then % 
# this val is always divisble by 4

id(n)%5


Return to python


Notes mentioning this note