最近在用python的时候,用到遍历多个变量:
import sys import math F58=11491939491.7 F=[11429229079.7,11374540753.7,11326394345.6,11283668004.5,11245493197.6,11211185188.5,11180195600.1,11152079195.3,11126470083.7,11103064338.2] G58=1243.038877 G=[1228.934579,1216.443834,1205.269029,1195.185247,1186.018752,1177.632816,1169.918081,1162.785842,1156.163245,1149.989794] I=[] for f in F: I.append(f/F58) J=[] for g in G: J.append(g/G58) K=[] for i,j in zip(I,J): K.append(j*0.9/i/0.1) L=[] for j,i in zip(J,I): L.append(j*0.5/i/0.5) M=[] for j,i in zip(J,I): M.append(j*0.1/i/0.9) print len(F),len(G),len(I),len(J),len(K),len(L),len(M) for f,g,i,j,k,l,m in zip(F,G,I,J,K,L,M): print f,' ',g,' ',i,' ',j,' ',k,' ',l,' ',m
用zip函数压缩到一个元组上。