Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   list.join()... re.join()...? Do they exist? (newbie questions...) (http://www.velocityreviews.com/forums/t349767-list-join-re-join-do-they-exist-newbie-questions.html)

googleboy 10-01-2005 12:39 PM

list.join()... re.join()...? Do they exist? (newbie questions...)
 
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


Benji York 10-01-2005 12:56 PM

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




All times are GMT. The time now is 01:04 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57