语法
a if b else c是Python中的三元运算符,
a其条件
b为true;否则为
c。可以在理解语句中使用:
>>> [a if a else 2 for a in [0,1,0,3]][2, 1, 2, 3]
因此,对于您的示例,
table = ''.join(chr(index) if index in ords_to_keep else replace_with for index in xrange(15))

语法
a if b else c是Python中的三元运算符,
a其条件
b为true;否则为
c。可以在理解语句中使用:
>>> [a if a else 2 for a in [0,1,0,3]][2, 1, 2, 3]
因此,对于您的示例,
table = ''.join(chr(index) if index in ords_to_keep else replace_with for index in xrange(15))