python 列表解析或推导(list comprehension)中的if else
python吧
全部回复
仅看楼主
level 12
like_python 楼主
python 列表解析或推导(list comprehension)中的if else
http://www.douban.com/note/325865653/
2014年02月07日 10点02分 1
level 15
一行代码的可以用and和or分别替换if和else
print (list(map(lambda i:(i[:1] is not '-' and i or i[1:]).isdigit() is False and -99 or int(i),a)))
print ([(i[:1] is not '-' and i or i[1:]).isdigit() is False and -99 or int(i) for i in a])
2014年02月07日 13点02分 5
1