''. join (list) is pretty big. However, I notice that I very often have to add extra characters to the beginning and end. I did this in several ways, but it seems to me that there is a more readable way that I cannot think of.
Is there an elegant way to handle it? Did I just change my mind about this?
For instance:
["column1", "column2", "column3"]
Required Conclusion:
| column1 | column2 | column3 |
Code without beginning and end (short!)
print ' | '.join(mylist)
With head and tail:
print ' | ' + ' | '.join(mylist) + ' | ' print ' | ', ' | '.join(mylist), ' | ' print " | {} | ".format(' | '.join(mylist)) print ' | '.join([''] + mylist + ['']) (ugh)
source share