Is there an easy way (hopefully a one liner) to replace '' with something like '-'?
Many thanks.
tup = (1,2,'ABC','','','','text')
Is there an easy way (hopefully a one liner) to replace '' with something like '-'?
Many thanks.
tup = (1,2,'ABC','','','','text')
How about the following?
tuple('-' if x == '' else x for x in tup)
As Felix Kling comments, tuples are immutable, so the best you can do is to return a new one.
tuple(x if x != '' else '-' for x in tup), since the usual, expected case is non-empty.tuple(x if x else '-' for x in tup)False, 0, [], etc.