The Seven Year Itch.

MENU

Python 中lambda与三元表达式的配合

December 16, 2017 • Read: 280 • Python

简单写个容易理解的

ss = lambda x, y: x if x > y else y
print(2,6)
与filter配合

ss_list = [0, 1, 1, 0, 0, 0]

ss = filter(lambda x: True if x != 1 else False, ss_list)

print(list(ss))

list与tuple的互换

auths = '1,2,3,4,5,6,7,8,9'
ss = list(map(lambda v: int(v), auths.split(',')))
print(ss)

auths2 = [1, 2, 3, 4, 5, 6]
ss2 = tuple(map(lambda v: int(v) if v != '' else None, auths2))
print(ss2)
Tags: None
Archives QR Code
QR Code for this page
Tipping QR Code