looping list problem

Paul McGuire ptmcg at austin.rr.com
Tue Aug 16 15:34:46 CEST 2005

Well, you are returning prematurely from a for loop, so that is why you
are only getting the first value.  Its just like:

for i in range(1000000):
    return i

It doesn't matter how big the range is you are iterating over, you'll
return on the first element and that's it.

If what you want is the list, then return the list:

hiddennavelements = navstring.split(' ')
return hiddennavelements

I think Fredrik Lundh was trying to accommodate your mixed thinking by
assuming your code was from a generator function.  With a generator,
you *can* return successive elements of a list, but you use the 'yield'
keyword instead of 'return', and repeated calls to the generator return
each successive value.

-- Paul

More information about the Python-list mailing list