On 20 Aug 2013 09:42, <eschneide...@comcast.net> wrote: > > I'm trying to replace the blank(_) with the letter typed in by the user, in the appropriate blank(_) spot where the letter should be (where is in the letters list). > > letters='abcdefg' > blanks='_ '*len(letters) > print('type letter from a to g') > print(blanks) > input1=input() > for i in range(len(letters)): > if letters[i] in input1: > blanks = blanks[:i] + letters[i] + blanks[i+1:] > > > What am I doing wrong in this code? > > Thanks > Eric
First, don't use range(len(iterable)). It's bad practise, and you will have to use iterable[i] all the time. Try for i, letter in enumerate(letters): If you are modifying a string in-place, you could change it into a list, then back. blankslst = list(blanks) ... blankslst[i] = letters[i] # or 'letter' if you used enumerate() ... blanks = ''.join(blankslst) Now, why are you not printing the `blanks` string again?
-- http://mail.python.org/mailman/listinfo/python-list