Is it possible to use 'else' in a python list comprehension?
- by Josh
Here is the code I was trying to turn into a list comprehension:
table = ''
for index in xrange(256):
if index in ords_to_keep:
table += chr(index)
else:
table += replace_with
Is there a way to add the else statement to this comprehension?
table = ''.join(chr(index) for index in xrange(15) if index in ords_to_keep)
Also, would I be right in concluding that a list comprehension is the most efficient way to do this?