Replace empty string in tuple

Is there an easy way (hopefully one liner) to replace “something like” - “?
Thanks a lot.

tup = (1,2,'ABC','','','','text')
+5
source share
1 answer

What about the next one?

 tuple('-' if x == '' else x for x in tup)

Like Felix Kling comments, tuples are immutable , so the best thing you can do is to bring back a new one.

+15
source

All Articles