ONE LINERS IN PYTHON

These are the top 6 liners in Python but there can be any number of one liner. So comment the one liner if you know.

SWAP TWO VARIABLES

a , b = b , a

SPACE SEPARATED INPUT

mylist = list(input().split())

FACTORIAL OF A NUMBER

reduce(lambda x,y:x*y, range(1,n+1))

LIST COMPREHENSION

sqres= [x*x for x in range (11)]

FIBONACCI SERIES

fib = lambda x:x if x<=1 else fib(x-1) + fib(x-2)

SUBSETS OF A SET

from itertools import combinations

print(list(combinations([1,2,3,4],2)))

Leave a comment

Design a site like this with WordPress.com
Get started