def gcd(a,b): if b==0: return a else: return gcd(b,a%b)
Month: March 2017
Remove a specific element from a string
string=’pandey’
string=list(string)
string.remove(‘p’)
print ”.join(str(e) for e in string)
Repeat string certain length python 2
from itertools import cycle, islice
def srepeat(string, n):
return ''.join(islice(cycle(string), n))
Remove a specific element from list python 2
li=[0,2,3,8,10,0]
li=[x for x in li if x!=0]
print li
[2,3,8,10]
Subtract a value from every number in a list python 2
a
=[1,2,3,4,5,6]
a[:]=[x-1 for x in a]
print a
[0,1,2,3,4,5]
Take more than one input in one line python 2
map(int,raw_input().split())
e.g m,n=map(int,raw_input().split())
here m,n is accept two value in same line space seprated
List input in python 2
list_new=[int(x) for x in raw_input().split()]
Python 2
Reverse a integer in python
def rev(n):
return int(str(n)[::-1])