Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.015 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'modifying': 0.07; 'string': 0.09; 'back.': 0.09; 'list).': 0.09; 'typed': 0.09; 'cc:addr:python-list': 0.11; "'letter'": 0.16; 'code?': 0.16; 'in- place,': 0.16; 'appropriate': 0.16; 'wrote:': 0.18; 'trying': 0.19; '(where': 0.19; 'aug': 0.22; 'cc:addr:python.org': 0.22; 'replace': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; '>': 0.26; 'first,': 0.26; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; "skip:' 10": 0.31; 'could': 0.34; 'subject:with': 0.35; 'received:google.com': 0.35; 'doing': 0.36; 'thanks': 0.36; 'should': 0.36; 'wrong': 0.37; 'list,': 0.38; 'bad': 0.39; 'letters': 0.60; 'spot': 0.65; 'user,': 0.69; 'again?': 0.84; 'subject:letter': 0.84; 'to:addr:comcast.net': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=QvPo0IfU0GS6Nw/9o48/1lqt1/j9UMrSy9+GjRnVyqg=; b=B+N0I9ZvWH1l5EK1KxcBCK8fu/QYikJSom1ZEgd+1TfJ9VrrGv+WXsNe3uI+5akMx+ bRh0Uj4HoM80l1k31PSGbkmoKRgRFEXqfzmfa3ZrgNUqpxqWHvbOPjaUM+mPtp3V31pP oR016BcUYKqyO53EQJ2p9ccvWM6BjObt4JX54qvOKtTL8po6YdSP3Yeqwz9y6VdJfNIF YHBOPfjV247pMaV3XcW2ObUJNbNkXBE1IGlBJYYETP8CP04uuKY1eLHR4RrMwbxTfUiG eULBXDb5/EV3rY/BGSYla44IZ5QGnLUFKoo/tKEZ615fmJosWqqD1PkDDJ9v7n+sh5h2 iIWA== MIME-Version: 1.0 X-Received: by 10.224.12.146 with SMTP id x18mr35504qax.110.1376990215989; Tue, 20 Aug 2013 02:16:55 -0700 (PDT) In-Reply-To: <2bdbd16f-a676-4973-9866-db93b1b9cd9b@googlegroups.com> References: <2bdbd16f-a676-4973-9866-db93b1b9cd9b@googlegroups.com> Date: Tue, 20 Aug 2013 10:16:55 +0100 Subject: Re: Replace blanks with letter From: =?ISO-8859-1?Q?F=E1bio_Santos?= To: eschneider92@comcast.net Content-Type: multipart/alternative; boundary=089e0149d2ccaf0c9104e45d84e7 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 80 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1376990224 news.xs4all.nl 16006 [2001:888:2000:d::a6]:59317 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52731 --089e0149d2ccaf0c9104e45d84e7 Content-Type: text/plain; charset=ISO-8859-1 On 20 Aug 2013 09:42, 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? --089e0149d2ccaf0c9104e45d84e7 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable


On 20 Aug 2013 09:42, <eschn= eider92@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 i= s in the letters list).
>
> letters=3D'abcdefg'
> blanks=3D'_ '*len(letters)
> print('type letter from a to g')
> print(blanks)
> input1=3Dinput()
> for i in range(len(letters)):
> =A0 =A0 if letters[i] in input1:
> =A0 =A0 =A0 =A0 blanks =3D 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 prac= tise, 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 =3D list(blanks)
...
blankslst[i] =3D letters[i]=A0 # or 'letter' if you used enumerate(= )
...
blanks =3D ''.join(blankslst)

Now, why are you not printing the `blanks` string again?

--089e0149d2ccaf0c9104e45d84e7--