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


Groups > comp.lang.python > #75943

Re: how to get the ordinal number in list

From Ned Batchelder <ned@nedbatchelder.com>
Subject Re: how to get the ordinal number in list
Date 2014-08-09 08:16 -0400
References <53E658CD.5020904@gmail.com> <CACwCsY7icE7X2upr0auNhe37xh5HdC09Ad4yaetqpo+fcoBRYg@mail.gmail.com> <53E65BFE.1060309@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.12791.1407586582.18130.python-list@python.org> (permalink)

Show all headers | View raw


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 <elearn2014@gmail.com> 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

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


Thread

Re: how to get the ordinal number in list Ned Batchelder <ned@nedbatchelder.com> - 2014-08-09 08:16 -0400

csiph-web