Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3a.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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:error': 0.03; '#if': 0.07; 'returns,': 0.09; 'def': 0.12; 'question.': 0.14; '"long': 0.16; 'commented': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'iterating': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:192.168.1.4': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'putting': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'either.': 0.24; 'string,': 0.24; 'header:In-Reply-To:1': 0.27; "doesn't": 0.30; 'characters': 0.30; 'skip:( 20': 0.30; 'work.': 0.31; 'received:84': 0.35; 'doing': 0.36; 'list': 0.37; 'list.': 0.37; 'work?': 0.38; 'to:addr:python-list': 0.38; 'list,': 0.38; 'to:addr:python.org': 0.39; 'subject: ': 0.61; "you're": 0.61; 'skip:n 10': 0.64; 'more': 0.64; 'here': 0.66; '800': 0.91; 'subject:Lists': 0.91 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=ceBcrxzM c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=aoAcgTy3oA8A:10 a=ihvODaAuJD4A:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=FdtYVtyxehw-CYTrMdIA:9 a=4e2yLd1WJSRtPgyM:21 a=BAhS04C72mqQVUXD:21 a=QEXdDO2ut3YA:10 a=quqSHGLc1FYA:10 X-AUTH: mrabarnett:2500 Date: Thu, 23 Oct 2014 00:09:54 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: I am out of trial and error again Lists References: In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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: 66 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1414019406 news.xs4all.nl 2849 [2001:888:2000:d::a6]:35928 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:79479 On 2014-10-22 23:30, Seymore4Head wrote: > On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head > wrote: > > One more question. > if y in str(range(10) > Why doesn't that work. In what way doesn't it work? If you want to know what it returns, print it out. > I commented it out and just did it "long hand" > > def nametonumber(name): > lst=[] > nx=[] > for x in (name): You don't need to put the parens around name... > lst.append(x) > for y in (lst): ...or around lst. You're iterating over a string, putting its characters into a list, and then iterating over that list. You're doing more work than you need to! > #if y in str(range(10)): > if y in "1234567890": > nx.append(y) > if y in " -()": > nx.append(y) > if y in "abc": > nx.append("2") > if y in "def": > nx.append("3") > if y in "ghi": > nx.append("4") > if y in "jkl": > nx.append("5") > if y in "mno": > nx.append("6") > if y in "pqrs": > nx.append("7") > if y in "tuv": > nx.append("8") > if y in "wxyz": > nx.append("9") > number="".join(str(e) for e in nx) The list nx already contains strings, so you don't need str here. > return (number) You don't need the parens here either. > a="1-800-getcharter" > print (nametonumber(a))#1800 438 2427 837 > a="1-800-leo laporte" > print (nametonumber(a)) > a="1 800 callaprogrammer" > print (nametonumber(a)) >