如何在Python中执行以下操作?
row = [unicode(x.strip()) for x in row if x is not None else '']
实质上:
我有一个清单l:
l = [22, 13, 45, 50, 98, 69, 43, 44, 1]
对于45以上的数字,我想加1; 对于小于它的数字,5.
我试过了
[x+1 for x in l if x >= 45 else x+5]
但它给了我一个语法错误.我怎样才能实现if- else在列表理解这样吗?
我想比较2个iterables并打印出两个iterables中出现的项目.
>>> a = ('q', 'r')
>>> b = ('q')
# Iterate over a. If y not in b, print y.
# I want to see ['r'] printed.
>>> print([ y if y not in b for y in a])
                              ^
但是它给了我一个无效的语法错误^.这个lamba函数有什么问题?