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


Groups > comp.lang.python > #75942

Re: how to get the ordinal number in list

From Johannes Bauer <dfnsonfsduifb@gmx.de>
Newsgroups comp.lang.python
Subject Re: how to get the ordinal number in list
Date 2014-08-09 14:13 +0200
Organization albasani.net
Message-ID <ls538p$8c4$1@news.albasani.net> (permalink)
References <mailman.12776.1407550960.18130.python-list@python.org>

Show all headers | View raw


On 09.08.2014 19:22, 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))

HTH,
Johannes

-- 
>> Wo hattest Du das Beben nochmal GENAU vorhergesagt?
> Zumindest nicht öffentlich!
Ah, der neueste und bis heute genialste Streich unsere großen
Kosmologen: Die Geheim-Vorhersage.
 - Karl Kaos über Rüdiger Thomas in dsa <hidbv3$om2$1@speranza.aioe.org>

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


Thread

how to get the ordinal number in list luofeiyu <elearn2014@gmail.com> - 2014-08-09 10:22 -0700
  Re: how to get the ordinal number in list Johannes Bauer <dfnsonfsduifb@gmx.de> - 2014-08-09 14:13 +0200
  Re: how to get the ordinal number in list Rustom Mody <rustompmody@gmail.com> - 2014-08-10 10:45 -0700
    Re: how to get the ordinal number in list Rustom Mody <rustompmody@gmail.com> - 2014-08-10 11:00 -0700
  Re: how to get the ordinal number in list ismeal shanshi <stuffstorehouse2014@gmail.com> - 2014-08-10 16:56 -0700

csiph-web