Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52731

Re: Replace blanks with letter

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 <fabiosantosart@gmail.com>
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; '&gt;': 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 Fábio Santos <fabiosantosart@gmail.com>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.54.1376990224.19984.python-list@python.org> (permalink)
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

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On 20 Aug 2013 09:42, <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?
>
> 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?

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Replace blanks with letter eschneider92@comcast.net - 2013-08-20 01:35 -0700
  Re: Replace blanks with letter Fábio Santos <fabiosantosart@gmail.com> - 2013-08-20 10:16 +0100
  Re: Replace blanks with letter Peter Otten <__peter__@web.de> - 2013-08-20 11:19 +0200
  Re: Replace blanks with letter eschneider92@comcast.net - 2013-08-20 13:45 -0700
    Re: Replace blanks with letter Dave Angel <davea@davea.name> - 2013-08-20 21:54 +0000
  Re: Replace blanks with letter eschneider92@comcast.net - 2013-08-21 00:49 -0700
    Re: Replace blanks with letter Chris Angelico <rosuav@gmail.com> - 2013-08-21 19:24 +1000
    Re: Replace blanks with letter Dave Angel <davea@davea.name> - 2013-08-21 11:42 +0000
    Re: Replace blanks with letter John Gordon <gordon@panix.com> - 2013-08-21 14:35 +0000
  Re: Replace blanks with letter eschneider92@comcast.net - 2013-08-22 15:42 -0700
    Re: Replace blanks with letter Dave Angel <davea@davea.name> - 2013-08-23 01:28 +0000
  Re: Replace blanks with letter eschneider92@comcast.net - 2013-08-22 15:44 -0700

csiph-web