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!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'output': 0.05; 'indices': 0.07; 'list).': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'spaces': 0.09; 'typed': 0.09; '"_"': 0.16; 'code?': 0.16; 'email addr:comcast.net': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'appropriate': 0.16; 'wrote:': 0.18; 'trying': 0.19; '(where': 0.19; 'header:User-Agent:1': 0.23; 'replace': 0.24; 'initial': 0.24; 'looks': 0.24; 'header:X-Complaints-To:1': 0.27; "i'm": 0.30; 'work.': 0.31; 'code': 0.31; "skip:' 10": 0.31; 'subject:with': 0.35; 'add': 0.35; 'adjust': 0.36; 'doing': 0.36; 'should': 0.36; 'wrong': 0.37; 'two': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'letters': 0.60; 'spot': 0.65; 'user,': 0.69; 'subject:letter': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Replace blanks with letter Date: Tue, 20 Aug 2013 11:19:31 +0200 Organization: None References: <2bdbd16f-a676-4973-9866-db93b1b9cd9b@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084bcf2.dip0.t-ipconnect.de User-Agent: KNode/4.7.3 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1376990390 news.xs4all.nl 16006 [2001:888:2000:d::a6]:33839 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52732 eschneider92@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? `blanks` has two chars per letter in `letters`. If you change the initial value to blanks = "_" * len(letters) your code should work. If you think the output looks better with spaces you have to adjust the indices -- or you add spaces for printing only with print(" ".join(blanks))