We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
change i+=1 to i = i+1 it will work
below is my program it works fine:
!/bin/python
import sys
str_new = list(raw_input().strip())
if (len(str_new)>100)|(1>len(str_new)):
sys.exit(1)
i =0
while i <(len(str_new)-1):
if str_new[i] == str_new[i+1]:
del str_new[i]
del str_new[i]
i = max(i-1,0)
if len(str_new) == 0:
print "Empty String"
break
else:
i=i+1
else:
print "".join(str_new)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Super Reduced String
You are viewing a single comment's thread. Return to all comments →
change i+=1 to i = i+1 it will work below is my program it works fine:
!/bin/python
import sys
str_new = list(raw_input().strip())
if (len(str_new)>100)|(1>len(str_new)): sys.exit(1)
i =0 while i <(len(str_new)-1): if str_new[i] == str_new[i+1]: del str_new[i] del str_new[i] i = max(i-1,0) if len(str_new) == 0: print "Empty String" break else: i=i+1 else: print "".join(str_new)