Substitute for join()

Steve Purcell stephen_purcell at yahoo.com
Wed Mar 21 15:12:46 EST 2001


Daniel Klein wrote:
> I've got to make a script (written in version 2.0) to work on a machine
> running 1.5.2. The only incompatible line is one that uses the
> "".join(mylist) method. To 'get out of the woods' quickly, I substituted it
> with
> 
> s = ''
> for element in mylist: s = s + element
> 
> Is this the most efficient way to code this?

No. Instead, try:

    import string
    s = string.join(mylist, '')

-Steve

-- 
Steve Purcell, Pythangelist
Get testing at http://pyunit.sourceforge.net/
Any opinions expressed herein are my own and not necessarily those of Yahoo




More information about the Python-list mailing list