Nice way of getting items from two lists

C GIllespie csgcsg39 at hotmail.com
Wed Mar 10 12:41:42 EST 2004


Dear All,

I have two equal size lists - list1, list2. Basically, each item in list 1
has a partner in list2. I was wanting to do something like
So if:
list1=['x','y','z']
list2=[1,2,3]

then if I did this 'for loop'
for name, value in list1,list2:
    print name, value

I would get
x,1
y,2
z,3

However, the 'loop' does not work. I could get what I want using
range(len(list1)), but I'm trying to improve my programming skills (fortran
background, so I'm weaning myself off GOTO's etc). So what's a nice way of
doing this?

Thanks

Colin





More information about the Python-list mailing list