> 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"
Well, I'm not sure how efficient it is, but the following seemed to do it for me: >>> a = 'abcd efgd 1234 fsdf gfds abcde 1234' >>> thing = '1234' >>> offsets = [i for i in range(len(a)) if a.startswith(thing, i)] >>> print offsets [10, 31] HTH, -tkc -- http://mail.python.org/mailman/listinfo/python-list