list.join()... re.join()...? Do they exist? (newbie questions...)

Discussion in 'Python' started by googleboy, Oct 1, 2005.

  1. googleboy

    googleboy Guest

    Hi.

    In some google posts I searched suggested that there was a list.join()
    thing that I assume works like string.join [which I notice is now
    deprecated in favour of S.join()]

    It seems that I have been misled.

    I start with a text file that I split up to run some formatting over
    the various sections with re.split. I want to join it back together
    again with a | delimeter and write it out to a new file. I looked for
    a re.join, but it seems that doesn't exist. I looked for a list.join
    after reading the aforementioned posts, but it doesn't seem to exist
    either.

    To get it to work I did this:


    List[0] = list0
    List[1] = list1
    List[2] = list2
    List[3] = list3
    cat_list = list0 + '|' + flatblurb + '|' + flatcontents + '|' + flates
    + '\n'
    file.write(concat_list)


    But it seems to me that there is probably something more pythonic than
    having to go about it in such a laborious fashion....

    Would someone be so kind as to fill me in?

    TIA!

    googleboy
    googleboy, Oct 1, 2005
    #1
    1. Advertising

  2. googleboy

    Benji York Guest

    Re: list.join()... re.join()...? Do they exist? (newbie questions...)

    googleboy wrote:
    > To get it to work I did this:
    >
    >
    > List[0] = list0
    > List[1] = list1
    > List[2] = list2
    > List[3] = list3
    > cat_list = list0 + '|' + flatblurb + '|' + flatcontents + '|' + flates
    > + '\n'
    > file.write(concat_list)
    >
    > But it seems to me that there is probably something more pythonic than
    > having to go about it in such a laborious fashion....


    Indeed. :)

    cat_list = '|'.join(List)
    --
    Benji York
    Benji York, Oct 1, 2005
    #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. Asfand Yar Qazi
    Replies:
    4
    Views:
    395
    Asfand Yar Qazi
    Nov 12, 2004
  2. Charles Krug
    Replies:
    7
    Views:
    361
    Harry George
    Jun 20, 2005
  3. Martin M.
    Replies:
    4
    Views:
    340
    Simon Brunning
    Dec 15, 2005
  4. Dave Rudolf
    Replies:
    1
    Views:
    299
    Kai-Uwe Bux
    May 17, 2006
  5. David A. Black
    Replies:
    2
    Views:
    222
    Tim Hunter
    Aug 19, 2004
Loading...

Share This Page