parashar.002
BAN USERdef prin_ser(n):
s = []
count = 1
for i in n:
if i != 0:
s.append(i)
else:
count+=1
if count >= 1:
while i < count:
s.append(0)
i += 1
return s
print prin_ser([1,2,3,4,0,6,0,1,0,3,1])
def rep(arr):
a = dict()
for el in arr:
a[el] = a.get(el,0)+1
for k,v in a.items():
if v > 1:
print "%d is repeated %d times"%(k,v)
print rep([1,2,3,3,4,4,5,5,5,6,7,7,8])
def sum(stri):
cnt = 0
for words in stri:
#print words
if words.isdigit():
cnt += int(words)
return cnt
return cnt
print sum('12awsd345')
def find_valid_exp(inp):
count = 0
cnt = 0
x = ')'
y = '('
for i in inp:
if i == x:
count+=1
else:
cnt += 1
if count == cnt:
return "valid"
else:
return "Invalid"
print find_valid_exp("(())())")
- parashar.002 January 15, 2016