循环遍历具有不同数量元素的列表

时间:2011-06-30 22:05:08

标签: python

  

我在C = []中得到了正确的结果,但我不能得到Tx等于:[42,68,86]            [23,45,59]           [40,68,85]           [30,56,72]   这是我无法做到的循环。我觉得这很容易,但我是新手,我找不到解决方案,我需要做的每件事都取决于这种类型的方法。如果可以,请给我一个亮点。

#T(1) = [T0 * C[1]+QIN[1]] multiply each element of T by each element of C adding each element of QIN
#T(2) = [T1 * C[2]+QIN[2]] multiply each element of T1 by each element of C2 adding each element of QIN2
#T(3) = [T2 * C[3]+QIN[3]] multiply each element of T2 by each element of C3 adding each element of QIN3
#T(4) = [T3 * C[4]+QIN[4]] multiply each element of T3 by each element of C3 adding each element of QIN4


QIN=[2.0, 3.0, 5.0, 2.0]
TIN=[10.0, 12.0, 13.0, 12.0] 

V=[2.0, 4.0, 5.0]

T0=[10.0, 11.0, 12.0]

for i in range(len(QIN)):
    C = []
    for v in V:
        C.append(v + QIN[i])
    print C 

for q in QIN:
    Tx = []
    for c in C:     
        for t in T0: 
            Tx.append(t * c + q)
    print Tx

1 个答案:

答案 0 :(得分:0)

Ts = [T0]
Tx = []
counter = 1
for T in Ts:
    for t in T:
        Ts.append([s[0] * s[1] + s[2] for s in izip(Ts[-1], C, QIN)])

我没有对此进行测试,因此如果不起作用则发表评论