[Tutor] List iteration

Simon Brunning SBrunning@trisystems.co.uk
Fri, 11 May 2001 12:16:03 +0100


> I would like to do some list iteration, is there a way to do something
> like
> this:
> 
> 
> # code start
> list_a = ['a', 'b', 'c']
> list_b = ['d', 'e', 'f']
> 
> for x, y in [list_a, list_b]:
> ....print  x + y          # hypo, this FAILS!! since the iterators length
> is shorter than the number of elements in list_a or list_b
 
If you are doing what I *think* you are doing, then the zip builtin might
help. Try:

for x, y in zip(list_a, list_b):
    print x + y

Cheers,
Simon Brunning
TriSystems Ltd.
sbrunning@trisystems.co.uk




-----------------------------------------------------------------------
The information in this email is confidential and may be legally privileged.
It is intended solely for the addressee. Access to this email by anyone else
is unauthorised. If you are not the intended recipient, any disclosure,
copying, distribution, or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot
accept liability for statements made which are clearly the senders own.