list item's position
Sean
sean at buildingonline.com
Wed Jan 19 22:38:22 EST 2005
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 Design and Marketing Agency
Celebrating our 9th year in business, founded Aug. 1995
Ph: 888-496-6648 ~ Fax: 949-496-0036
--> Web Design Agency site: http://www.BuildingOnline.net
--> Building Industry Portal: http://www.BuildingOnline.com
--> Building Industry News: http://www.BuildingOnline.com/news/
--> Home Plans: http://www.eHomePlans.com
"Bob Smith" <bob_smith_17280 at hotmail.com> wrote in message
news:csn747$3fq$1 at solaris.cc.vt.edu...
> 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
> find its value is so I can remove every element in the list before it so
> that the bar I found somewhere in the list becomes element 0... does that
> make sense?
>
> Thanks,
>
> Bob
More information about the Python-list
mailing list