5
votes

Is there an easy way (hopefully a one liner) to replace '' with something like '-'?
Many thanks.

tup = (1,2,'ABC','','','','text')
1
I hope you are aware that tuples are immutable. You can do it, but that will create a new tuple (so references might break). - Felix Kling
Why do people specifically want one-liners? - Ned Batchelder

1 Answers

15
votes

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.