美文网首页
python列表生成式&字典

python列表生成式&字典

作者: Jacqueline文萍 | 来源:发表于2018-10-17 09:28 被阅读0次

#Copy &deepcopy

from copyimport deepcopy

list1=[1,2,3,4]

list2=['a','b',list1]

list3=list2.copy()

#['a', 'b', [1, 2, 3, 4]]

list4=deepcopy(list2)

#['a', 'b', [1, 2, 3, 4]]

list1=[1,2]

print(list3)

#['a', 'b', [1, 2, 3, 4]]

print(list4)

#['a', 'b', [1, 2, 3, 4]]

list1.append('c')

print(list1)

#[1, 2, 'c']

print(list3)

#['a', 'b', [1, 2, 3, 4]]

print(list4)

#['a', 'b', [1, 2, 3, 4]]

list1=[i*ifor iin range(1,16)if i%2!=0]

print(list1)

#[1, 9, 25, 49, 81, 121, 169, 225]

list3=[i*jfor iin range(1,10)for jin range(i,10)]

print(list3)

#[1, 2, 3, 4, 5, 6, 7, 8, 9, 4, 6, 8, 10, 12, 14, 16, 18, 9, 12, 15, 18, 21, 24, 27, 16, 20, 24, 28, 32, 36, 25, 30, 35, 40, 45, 36, 42, 48, 54, 49, 56, 63, 64, 72, 81]

相关文章

网友评论

      本文标题:python列表生成式&字典

      本文链接:https://www.haomeiwen.com/subject/tphlzftx.html