find all index positions

Gary Herron gherron at islandtraining.com
Thu May 11 13:08:27 EDT 2006


Paul Rubin wrote:

>micklee74 at hotmail.com writes:
>  
>
>>say i have string like this
>>astring = 'abcd efgd 1234 fsdf gfds abcde 1234'
>>if i want to find which postion is 1234, how can i achieve this...? i
>>want to use index() but it only give me the first occurence. I want to
>>know the positions of both "1234"
>>    
>>
>
>Most straightforwardly with re.findall -- see the docs.
>  
>
Not quite.  The findall will list the matching strings, not their 
positions. -- He'll get ['1234','1234'].  The finditer function will 
work for his requirements. See my other post  to this thread.



More information about the Python-list mailing list