當前位置:成語大全網 - 新華字典 - list=[2,3,5,6,7,8] mapping={2:10,3:12,8:30} pytho

list=[2,3,5,6,7,8] mapping={2:10,3:12,8:30} pytho

get()?

>>> list=[2,3,5,6,7,8]

>>> mapping={2:10,3:12,8:30}

>>> newlist = [ mapping.get(i,i) for i in tmplist ]

>>> print(newlist)

[10, 12, 5, 6, 7, 30]