Re: Separating elements from a list according to preceding element

2006-03-06 Thread Rob Cowie
Thanks everyone. I assumed there was something I had not considered... list slicing is that thing. The pyParsing example looks interesting - but for this case, a little too heavy. It doesn't really warrant including a third party module. Rob C -- http://mail.python.org/mailman/listinfo/python-l

Re: Separating elements from a list according to preceding element

2006-03-05 Thread Michael Spencer
Rob Cowie wrote: > I'm having a bit of trouble with this so any help would be gratefully > recieved... > > After splitting up a url I have a string of the form > 'tag1+tag2+tag3-tag4', or '-tag1-tag2' etc. The first tag will only be > preceeded by an operator if it is a '-', if it is preceded by n

Re: Separating elements from a list according to preceding element

2006-03-05 Thread Bruno Desthuilliers
Gerard Flanagan a écrit : > Alex Martelli wrote: > >>Gerard Flanagan <[EMAIL PROTECTED]> wrote: >>... >> >>>a = [ '+', 'tag1', '+', 'tag2', '-', 'tag3', '+', 'tag4' ] >>> >>>import itertools >>> >>>b = list(itertools.islice(a,0,8,2)) >>>c = list(itertools.islice(a,1,8,2)) >> >>Much as I love i

Re: Separating elements from a list according to preceding element

2006-03-05 Thread Paul McGuire
"Rob Cowie" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I'm having a bit of trouble with this so any help would be gratefully > recieved... > > After splitting up a url I have a string of the form > 'tag1+tag2+tag3-tag4', or '-tag1-tag2' etc. The first tag will only be > preceeded

Re: Separating elements from a list according to preceding element

2006-03-05 Thread Gerard Flanagan
Alex Martelli wrote: > Gerard Flanagan <[EMAIL PROTECTED]> wrote: > ... > > a = [ '+', 'tag1', '+', 'tag2', '-', 'tag3', '+', 'tag4' ] > > > > import itertools > > > > b = list(itertools.islice(a,0,8,2)) > > c = list(itertools.islice(a,1,8,2)) > > Much as I love itertools, this specific task wo

Re: Separating elements from a list according to preceding element

2006-03-05 Thread Gerard Flanagan
James Stroud wrote: > Gerard Flanagan wrote: > > Rob Cowie wrote: > > > >>I'm having a bit of trouble with this so any help would be gratefully > >>recieved... > >> > >>After splitting up a url I have a string of the form > >>'tag1+tag2+tag3-tag4', or '-tag1-tag2' etc. The first tag will only be >

Re: Separating elements from a list according to preceding element

2006-03-05 Thread Alex Martelli
Gerard Flanagan <[EMAIL PROTECTED]> wrote: ... > a = [ '+', 'tag1', '+', 'tag2', '-', 'tag3', '+', 'tag4' ] > > import itertools > > b = list(itertools.islice(a,0,8,2)) > c = list(itertools.islice(a,1,8,2)) Much as I love itertools, this specific task would be best expressed ad b = a[::2] c

Re: Separating elements from a list according to preceding element

2006-03-05 Thread James Stroud
Bruno Desthuilliers wrote: > Rob Cowie a écrit : > >> I'm having a bit of trouble with this so any help would be gratefully >> recieved... >> >> After splitting up a url I have a string of the form >> 'tag1+tag2+tag3-tag4', or '-tag1-tag2' etc. The first tag will only be >> preceeded by an operato

Re: Separating elements from a list according to preceding element

2006-03-05 Thread Bruno Desthuilliers
Rob Cowie a écrit : > I'm having a bit of trouble with this so any help would be gratefully > recieved... > > After splitting up a url I have a string of the form > 'tag1+tag2+tag3-tag4', or '-tag1-tag2' etc. The first tag will only be > preceeded by an operator if it is a '-', if it is preceded b

Re: Separating elements from a list according to preceding element

2006-03-05 Thread James Stroud
Gerard Flanagan wrote: > Rob Cowie wrote: > >>I'm having a bit of trouble with this so any help would be gratefully >>recieved... >> >>After splitting up a url I have a string of the form >>'tag1+tag2+tag3-tag4', or '-tag1-tag2' etc. The first tag will only be >>preceeded by an operator if it is a

Re: Separating elements from a list according to preceding element

2006-03-05 Thread James Stroud
Rob Cowie wrote: > I'm having a bit of trouble with this so any help would be gratefully > recieved... > > After splitting up a url I have a string of the form > 'tag1+tag2+tag3-tag4', or '-tag1-tag2' etc. The first tag will only be > preceeded by an operator if it is a '-', if it is preceded by n

Re: Separating elements from a list according to preceding element

2006-03-05 Thread Gerard Flanagan
Gerard Flanagan wrote: > Rob Cowie wrote: > > I'm having a bit of trouble with this so any help would be gratefully > > recieved... > > > > After splitting up a url I have a string of the form > > 'tag1+tag2+tag3-tag4', or '-tag1-tag2' etc. The first tag will only be > > preceeded by an operator i

Re: Separating elements from a list according to preceding element

2006-03-05 Thread Ben Cartwright
Rob Cowie wrote: > I wish to derive two lists - each containing either tags to be > included, or tags to be excluded. My idea was to take an element, > examine what element precedes it and accordingly, insert it into the > relevant list. However, I have not been successful. > > Is there a better wa

Re: Separating elements from a list according to preceding element

2006-03-05 Thread Gerard Flanagan
Rob Cowie wrote: > I'm having a bit of trouble with this so any help would be gratefully > recieved... > > After splitting up a url I have a string of the form > 'tag1+tag2+tag3-tag4', or '-tag1-tag2' etc. The first tag will only be > preceeded by an operator if it is a '-', if it is preceded by n