Re: joining strings question
- From: Robert Bossy <Robert.Bossy@xxxxxxxxxxxx>
- Date: Fri, 29 Feb 2008 16:54:57 +0100
patrick.waldo@xxxxxxxxx wrote:
Hi all,As others already said, the data structure is quite unfit. Therefore I give you one of the ugliest piece of code I've produced in years:
I have some data with some categories, titles, subtitles, and a link
to their pdf and I need to join the title and the subtitle for every
file and divide them into their separate groups.
So the data comes in like this:
data = ['RULES', 'title','subtitle','pdf',
'title1','subtitle1','pdf1','NOTICES','title2','subtitle2','pdf','title3','subtitle3','pdf']
What I'd like to see is this:
[RULES', 'title subtitle','pdf', 'title1 subtitle1','pdf1'],
['NOTICES','title2 subtitle2','pdf','title3 subtitle3','pdf'], etc...
I've racked my brain for a while about this and I can't seem to figure
it out. Any ideas would be much appreciated.
r = []
for i in xrange(0, len(data), 7):
r.append([data[i], ' '.join((data[i+1], data[i+2],)), data[i+3], ' '.join((data[i+4], data[i+5],)), data[i+6]])
print r
Cheers,
RB
.
- References:
- joining strings question
- From: patrick . waldo
- joining strings question
- Prev by Date: Re: joining strings question
- Next by Date: Problem round-tripping with xml.dom.minidom pretty-printer
- Previous by thread: Re: joining strings question
- Next by thread: Re: joining strings question
- Index(es):
Relevant Pages
|