Ridhibhan.19
BAN USERdef shortstringinBigString(main,sub):
lenm = len(main)
lens = len(sub)
for i in range(lenm):
if main[i:i+lens] == sub:
print True
break
else:
print false
def findSubsetAnagram(l):
c = {}
for item in l:
j = ''.join(sorted(item))
c.setdefault(j,[]).append(item)
for k,v in c.items():
print v
this code won't work if there are no negative numbers
- Ridhibhan.19 September 14, 2017def RepeatingNum(a, n):
c={}
count = 0
for item in a:
if item in c:
c[item]+=1
else:
c[item]=1
for k,v in c.iteritems():
if v == n:
for i in range(len(a)):
if a[i]==k:
print (i,i+n-1)
exit()
elif v!=n:
continue
print(-1,-1)
a = [0,2,3,3,3,3,10,10,10]
n = 4
RepeatingNum(a,n)
def getSentence(txt, dico):
start = 0
cur = 0
d=[]
t = 0
if len(txt) == 0:
return None
while cur < len(txt):
cur += 1
item = txt[start:cur]
if item in dico:
t = cur+1
temp = txt[start:t]
if temp in dico:
d.append(txt[start:t])
t=t+1
elif ''.join(d[-1:]) != item:
d.append(item)
txt = txt[cur:]
cur = 0
else:
txt = txt[cur:]
cur = 0
print ' '.join(d)
txt = 'iamastudentfromwaterloo'
dico = {"from", "waterloo", "hi", "am", "yes", "i", "a", "student"}
getSentence(txt,dico)
input = "How are you, Mr. X?"
h = ['?', ' ' ,'.' ,',']
for i in h:
if i in input:
j = input.replace(i,'|')
input = j
print j
a = raw_input("enter the string")
c = filter(a.isalpha, a)
c = c.lower
rev_c = c[::-1]
if c == rev_c:
print "Palindrome"
else:
print "Not a palindrome"
you need to add int() to len(l)/n+1 as the float values won't be supported
- Ridhibhan.19 December 20, 2018