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
> 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,
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
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:
>
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
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
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
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:
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