[Python-Dev] Stupid Python Tricks, Volume 38 Number 1

Tim Peters tim.one@home.com
Sat, 20 Jan 2001 01:30:42 -0500


I had a huge string and wanted to put a double-quote on each end.  The
boring:

    '"' + huge + '"'

does the job, but is inefficent <snort>.  Then this transparent variation
sprang unbidden from my hoary brow:

    huge.join('""')

*That* should put to rest the argument over whether .join() is more properly
a method of the separator or the sequence -- '""'.join(huge) instead would
look plain silly <wink>.

not-entirely-sure-i'm-channeling-on-this-one-ly y'rs  - tim