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
--------------------------------------------------------
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to