Concatenating strings

Discussion in 'Python' started by John Henry, Jul 1, 2006.

  1. John Henry

    John Henry Guest

    Sorry if this is a dumb question.

    I have a list of strings (some 10,000+) and I need to concatenate them
    together into one very long string. The obvious method would be, for
    example:

    alist=["ab","cd","ef",.....,"zzz"]
    blist = ""
    for x in alist:
    blist += x

    But is there a cleaner and faster way of doing this?

    Thanks,
    John Henry, Jul 1, 2006
    #1
    1. Advertising

  2. John Henry

    Robert Kern Guest

    John Henry wrote:
    > Sorry if this is a dumb question.
    >
    > I have a list of strings (some 10,000+) and I need to concatenate them
    > together into one very long string. The obvious method would be, for
    > example:
    >
    > alist=["ab","cd","ef",.....,"zzz"]
    > blist = ""
    > for x in alist:
    > blist += x
    >
    > But is there a cleaner and faster way of doing this?


    blist = ''.join(alist)

    --
    Robert Kern

    "I have come to believe that the whole world is an enigma, a harmless enigma
    that is made terrible by our own mad attempt to interpret it as though it had
    an underlying truth."
    -- Umberto Eco
    Robert Kern, Jul 1, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stan Horwitz
    Replies:
    2
    Views:
    2,731
    Stan Horwitz
    Feb 15, 2006
  2. Replies:
    11
    Views:
    613
    Karl Heinz Buchegger
    Apr 8, 2005
  3. John Henry

    Concatenating strings

    John Henry, Jul 1, 2006, in forum: Python
    Replies:
    1
    Views:
    301
    Steven Bethard
    Jul 1, 2006
  4. EHC

    concatenating strings

    EHC, Dec 15, 2006, in forum: Python
    Replies:
    3
    Views:
    317
    Caleb Hattingh
    Dec 16, 2006
  5. c

    Help me with Concatenating strings

    c, Sep 24, 2006, in forum: C Programming
    Replies:
    21
    Views:
    600
    Chris Torek
    Oct 15, 2006
Loading...

Share This Page