Is there a better way than what I am doing?
word = "baab"
word = word[:word.find('a')]+word[word.find('a')+1:]
print word #bab
You can use the string replace function with a maximum count:
s = s.replace('a','',1)
as in the following transcript:
>>> s = "baab"
>>> s = s.replace('a','',1)
>>> s
'bab'
From the documentation:
str.replace(old, new[, count])
Return a copy of the string with all occurrences of substring
old
replaced bynew
. If the optional argumentcount
is given, only the firstcount
occurrences are replaced.