python 列表解析

 

list_a = [1, 2, 3]
list_d = [i for i in list_a]#[1, 2, 3]
list_e = [i*j for i in list_a for j in list_c]#[4,5,6,10,12,12,15,18]
list_f = [i*j for i,j in zip(list_a,list_c)]#[4, 10, 18]
list_g = [i for i in list_a if i%2 == 0]#[2]


#结合range()函数,range(start, stop[, step])
list_h = list(range(3)) # [0, 1, 2]
list_i = list(range(3,7)) # [3, 4, 5, 6]
list_j = list(range(3,9,2)) # [3, 5, 7]
#找出100以内的能够被3整除的正整数
list_k = list(range(3,100,3)) # list_k == [3, 6, 9, ..., 96, 99]
 
posted @ 2022-08-30 16:49  遇事不决,量子力学  阅读(30)  评论(0编辑  收藏  举报