How to iterate over two lists?

后端 未结 2 927
孤独总比滥情好
孤独总比滥情好 2021-01-14 06:35

I am trying to do something in pyGTk where I build a list of HBoxes:

self.keyvalueboxes = []
for keyval in range(1,self.keyvaluelen):
    self.keyvalueboxes.a         


        
相关标签:
2条回答
  • 2021-01-14 06:51

    If your list are of equal length use zip

    >>> x = ['a', 'b', 'c', 'd']
    >>> y = [1, 2, 3, 4]
    >>> z = zip(x,y)
    >>> z
    [('a', 1), ('b', 2), ('c', 3), ('d', 4)]
    >>> for l in z: print l[0], l[1]
    ... 
    a 1
    b 2
    c 3
    d 4
    >>> 
    
    0 讨论(0)
  • 2021-01-14 07:01

    Check out http://docs.python.org/library/functions.html#zip. It lets you iterate over two lists at the same time.

    0 讨论(0)
提交回复
热议问题