[Tutor] indexing question
Emad Nawfal
emadnawfal at gmail.com
Wed Sep 26 13:43:21 CEST 2007
Hi Tutors,
Is there a way to get the index of every occurence of a certain element in a
list. listname.index(element) gives me the index of the first occurence. For
example:
>>> t = 'we are we are we we we'.split()
>>> t
['we', 'are', 'we', 'are', 'we', 'we', 'we']
>>> for word in t:
if word =='we':
t.index(word)
0
0
0
0
0
Now I want the index of each 'we' in t. I want the result to be 0, 2, 4, 5,
6
How can I do that?
Thank you in anticipation?
--
لا أعرف مظلوما تواطأ الناس علي هضمه ولا زهدوا في إنصافه كالحقيقة.....محمد
الغزالي
Emad Soliman Nawfal
Indiana University, Bloomington
http://emadnawfal.googlepages.com
--------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070926/a8f6fefb/attachment-0001.htm
More information about the Tutor
mailing list