Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.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.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'that?': 0.05; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:number': 0.09; 'ordinal': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'sat,': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'aug': 0.22; 'print': 0.22; 'header:User- Agent:1': 0.23; 'received:comcast.net': 0.24; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'subject:list': 0.30; 'larry': 0.31; 'subject:the': 0.34; 'there': 0.35; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:x 10': 0.40; 'how': 0.40; 'even': 0.60; 'tell': 0.60; 'simple': 0.61; 'more': 0.64; 'subject:get': 0.81; '7:25': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ned Batchelder Subject: Re: how to get the ordinal number in list Date: Sat, 09 Aug 2014 08:16:08 -0400 References: <53E658CD.5020904@gmail.com> <53E65BFE.1060309@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: c-50-133-228-126.hsd1.ma.comcast.net User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: <53E65BFE.1060309@gmail.com> 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: 1407586582 news.xs4all.nl 2886 [2001:888:2000:d::a6]:54287 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:75943 On 8/9/14 1:35 PM, luofeiyu wrote: > >>> x=["x1","x3","x7","x5","x3"] > >>> x.index("x3") > 1 > if i want the result of 1 and 4 ? If you tell us more about your problem, and what you will do with the 1 and 4, there might be an even better way to do what you want. > > On 8/8/2014 7:25 PM, Larry Martell wrote: >> On Sat, Aug 9, 2014 at 1:22 PM, luofeiyu wrote: >>>>>> x=["x1","x3","x7","x5"] >>>>>> y="x3" >>> how can i get the ordinal number by some codes? >>> >>> for id ,value in enumerate(x): >>> if y==value : print(id) >>> >>> Is more simple way to do that? >> print x.index(y) > -- Ned Batchelder, http://nedbatchelder.com