Re: list item's position

2005-01-20 Thread Bengt Richter
On Wed, 19 Jan 2005 22:04:44 -0500, Bob Smith <[EMAIL PROTECTED]> wrote: >Hi, > >I have a Python list. I can't figure out how to find an element's >numeric value (0,1,2,3...) in the list. Here's an example of what I'm doing: > >for bar in bars: >if 'str_1' in bar and 'str_2' in bar: > p

Re: list item's position

2005-01-20 Thread Petr Prikryl
> On Wed, 19 Jan 2005 22:04:44 -0500, Bob Smith wrote: > > [...] how to find an element's numeric value (0,1,2,3...) > > in the list. Here's an example of what I'm doing: > > > > for bar in bars: > > if 'str_1' in bar and 'str_2' in bar: > >print bar > > > > This finds the right bar,

Re: list item's position

2005-01-19 Thread John Machin
On Wed, 19 Jan 2005 22:02:51 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote: > >See Mark's post, if you "need to know the index of something" this is >the perfect case for enumerate (assuming you have at least Python 2.3): But the OP (despite what he says) _doesn't_ need to know the index of th

Re: list item's position

2005-01-19 Thread Stephen Thorne
On Wed, 19 Jan 2005 22:04:44 -0500, Bob Smith <[EMAIL PROTECTED]> wrote: > Hi, > > I have a Python list. I can't figure out how to find an element's > numeric value (0,1,2,3...) in the list. Here's an example of what I'm doing: > > for bar in bars: > if 'str_1' in bar and 'str_2' in bar: >

Re: list item's position

2005-01-19 Thread Steven Bethard
Bill Mill wrote: 2 solutions: In [98]: bars = ["str", "foobaz", "barbaz", "foobar"] In [99]: for bar in bars: : if 'bar' in bar and 'baz' in bar: : print bar : print bars.index(bar) : barbaz 2 In [100]: for i in range(len(bars)): .: if 'bar

Re: list item's position

2005-01-19 Thread Sean
Not sure if this is what you are looking for but... >>> li = ['this','is','a','list','of','strings'] >>> li = [l for l in li if li.index(l) >= li.index('a')] >>> li ['a', 'list', 'of', 'strings'] >>> -- Sean Berry ~ Internet Systems Programmer BuildingOnline Inc. The Building Industry's Web De

Re: list item's position

2005-01-19 Thread Bill Mill
2 solutions: In [98]: bars = ["str", "foobaz", "barbaz", "foobar"] In [99]: for bar in bars: : if 'bar' in bar and 'baz' in bar: : print bar : print bars.index(bar) : barbaz 2 In [100]: for i in range(len(bars)): .: if 'bar' in bars[i] a

Re: list item's position

2005-01-19 Thread Mark McEahern
Bob Smith wrote: Hi, I have a Python list. I can't figure out how to find an element's numeric value (0,1,2,3...) in the list. Here's an example of what I'm doing: Use enumerate() (new in Python 2.3, IIRC). Otherwise: for i in range(len(sequence)): item = sequence[i] ... for bar in bars:

list item's position

2005-01-19 Thread Bob Smith
Hi, I have a Python list. I can't figure out how to find an element's numeric value (0,1,2,3...) in the list. Here's an example of what I'm doing: for bar in bars: if 'str_1' in bar and 'str_2' in bar: print bar This finds the right bar, but not its list position. The reason I need to f