By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,814 Members | 1,136 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,814 IT Pros & Developers. It's quick & easy.

loop iterators?

P: n/a
Hi I need to get a for loop to give me an element from a list and an
index number...
for example:

i = 0
l = ['a','b','c']
for e in l:
print l, i
i = i + 1

Is there a way to get rid of the i processing in this script?
Sorry I'm still trying to learn python tricks here...

Oct 17 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
In <11**********************@h48g2000cwc.googlegroups .com>, SpreadTooThin
wrote:
Hi I need to get a for loop to give me an element from a list and an
index number...
for example:

i = 0
l = ['a','b','c']
for e in l:
print l, i
i = i + 1

Is there a way to get rid of the i processing in this script?
for i, e in enumerate(l):
print i, e

Ciao,
Marc 'BlackJack' Rintsch

Oct 17 '06 #2

P: n/a
l = ['a','b','c']
for e in l:
print l, i
i = i + 1

Is there a way to get rid of the i processing in this script?
Sorry I'm still trying to learn python tricks here...

for i, e in enumerate(l):
print l, i

-tkc

Oct 17 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.