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

G

googleboy

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
 
B

Benji York

googleboy said:
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)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top