list.index() like...but returning lists (for avoiding '0' on multiples hits)

John Roth newsgroups at jhrothjr.com
Mon Dec 22 18:16:47 EST 2003


"Srinath Avadhanula" <srinathava_news at yahoo.com> wrote in message
news:mailman.58.1072133958.684.python-list at python.org...
> > but their results is not giving me the answer that i looking for...So,
here i
> > go...when i have myList = [2,4,2,0] ...myList.index(2) returns 0 (python
> > 2.2)....There is a built-in function-method that returns [0,2]?
> >
>
> This works...
>
> >>> a = [1,2,3,4]
> >>> a[:2]
> [1, 2]
> >>>

But what does that have to do with the question?

As far as I know, there is no such built-in for lists.
You can do something similar with the "re" module
for strings, but not for lists.

John Roth
>
> Srinath
>






More information about the Python-list mailing list