Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > loop iterators?

Reply
Thread Tools

loop iterators?

 
 
SpreadTooThin
Guest
Posts: n/a
 
      10-17-2006
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...

 
Reply With Quote
 
 
 
 
Marc 'BlackJack' Rintsch
Guest
Posts: n/a
 
      10-17-2006
In <(E-Mail Removed) .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

 
Reply With Quote
 
 
 
 
Tim Chase
Guest
Posts: n/a
 
      10-17-2006
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
Getting a loop to activate a loop above it Byte Python 4 03-24-2006 03:04 AM
Condition outside loop or separate loop for different condition? - Java 12 06-15-2005 08:50 AM
while loop in a while loop Steven Java 5 03-30-2005 09:19 PM
Loop the loop... =?Utf-8?B?VGltOjouLg==?= ASP .Net 2 02-16-2005 12:21 PM



Advertisments