In [43]: a =[1,2,3,4,5]
In [44]: b =[x*2for x in a]
In [45]: b
Out[45]:[2,4,6,8,10]
In [46]: c =[str(x)for x in a]
In [47]: c
Out[47]:['1','2','3','4','5']
2. 含有 if 条件
In [48]: a =range(11)
In [49]: b =[x*2for x in a if x%2==0]
In [50]: b
Out[50]:[0,4,8,12,16,20]
In [55]: c =[i*j for i inrange(3)for j inrange(3)]
In [56]: c
Out[56]:[0,0,0,0,1,2,0,2,4]
3. 含有 zip
In [57]: a =range(3)
In [58]: b =["a",'b','c']
In [59]: m =[str(x)+str(y)for x, y inzip(a,b)]
In [60]: m
Out[60]:['0a','1b','2c']
4. 含有字典
In [61]: d ={'a':1,'b':2,'c':3}
In [67]: n =[k+':'+str(v)for k, v in d.items()]
In [68]: n
Out[68]:['a:1','b:2','c:3']
5. 差集
In [72]: a =['1','2','3','4']
In [73]: b =['1','2','5','6']
In [74]: c =[x for x in a if x notin b]
In [75]: c
Out[75]:['3','4']
1. 单数据运算In [43]: a = [1,2,3,4,5]In [44]: b = [x*2 for x in a]In [45]: bOut[45]: [2, 4, 6, 8, 10]In [46]: c = [str(x) for x in a]In [47]: cOut[47]: ['1', '2', '3', '4', '5']2. 含有 if 条件In...