1.对于for循环前有命令操作
示例:
list = ['a.','b.','c.','d.']
img_ids = [i_id.strip('.') for i_id in list]
img_ids = ['a', 'b', 'c', 'd']
可以看到遍历list中的字符串而后对每一个遍历的字符串进行strip() 操作,而后形成一个新的字典。
2.多for值操作以及生成标签
>>>for x, y in [(1, 1), (2, 4), (3, 9)]:
>>>print(x,y)
>>>1 1
>>>2 4
>>>3 9
>>>for x, y in enumerate(['a', 'b', 'c']):
>>>print(x, y)
>>>0 a
>>>1 b
>>>2 c
3. 对生成列表添加条件判断
eg:
[x*x for x in range(1,11) if x%2==0 is not None ]
Out[8]: [4, 16, 36, 64, 100]
未完待续