Re: re beginner

2006-06-05 Thread SuperHik
WOW! Thanks for all the answers, even those not related to regular expressions tought me some stuff I wasn't aware of. I appreciate it very much. SuperHik wrote: > hi all, > > I'm trying to understand regex for the first time, and it would be very > helpful to get an example. I have an old(er)

Re: re beginner

2006-06-05 Thread John Machin
On 5/06/2006 10:30 PM, Bruno Desthuilliers wrote: > John Machin a écrit : >> On 5/06/2006 10:38 AM, Bruno Desthuilliers wrote: >> >>> SuperHik a écrit : >>> hi all, > (snip) > I have an old(er) script with the following task - takes a string I copy-pasted and wich always has t

Re: re beginner

2006-06-05 Thread John Machin
On 5/06/2006 7:47 PM, Fredrik Lundh wrote: > John Machin wrote: > >> Fantastic -- at least for the OP's carefully copied-and-pasted input. >> Meanwhile back in the real world, there might be problems with >> multiple tabs used for 'prettiness' instead of 1 tab, non-integer >> values, etc etc. >

Re: re beginner

2006-06-05 Thread Bruno Desthuilliers
Fredrik Lundh a écrit : > John Machin wrote: > >> Fantastic -- at least for the OP's carefully copied-and-pasted input. >> Meanwhile back in the real world, there might be problems with >> multiple tabs used for 'prettiness' instead of 1 tab, non-integer >> values, etc etc. > > > yeah, that's

Re: re beginner

2006-06-05 Thread Fredrik Lundh
SuperHik wrote: > I'm trying to understand regex for the first time, and it would be very > helpful to get an example. I have an old(er) script with the following > task - takes a string I copy-pasted and wich always has the same format: > > >>> print stuff > Yellow hat2 Blue shirt

Re: re beginner

2006-06-05 Thread Fredrik Lundh
John Machin wrote: > Fantastic -- at least for the OP's carefully copied-and-pasted input. > Meanwhile back in the real world, there might be problems with multiple > tabs used for 'prettiness' instead of 1 tab, non-integer values, etc etc. yeah, that's probably why the OP stated "which always h

Re: re beginner

2006-06-05 Thread Bruno Desthuilliers
John Machin a écrit : > On 5/06/2006 10:38 AM, Bruno Desthuilliers wrote: > >> SuperHik a écrit : >> >>> hi all, >>> (snip) >>> I have an old(er) script with the >>> following task - takes a string I copy-pasted and wich always has the >>> same format: >>> (snip) >>> >> def to_dict(items): >>

Re: re beginner

2006-06-04 Thread Paul McGuire
"John Machin" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On 5/06/2006 10:07 AM, Paul McGuire wrote: > > "John Machin" <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > >> Fantastic -- at least for the OP's carefully copied-and-pasted input. > >> Meanwhile back in

Re: re beginner

2006-06-04 Thread John Machin
On 5/06/2006 10:07 AM, Paul McGuire wrote: > "John Machin" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> Fantastic -- at least for the OP's carefully copied-and-pasted input. >> Meanwhile back in the real world, there might be problems with multiple >> tabs used for 'prettiness'

Re: re beginner

2006-06-04 Thread Paul McGuire
"John Machin" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Fantastic -- at least for the OP's carefully copied-and-pasted input. > Meanwhile back in the real world, there might be problems with multiple > tabs used for 'prettiness' instead of 1 tab, non-integer values, etc etc. > I

Re: re beginner

2006-06-04 Thread John Machin
On 5/06/2006 10:38 AM, Bruno Desthuilliers wrote: > SuperHik a écrit : >> hi all, >> >> I'm trying to understand regex for the first time, and it would be >> very helpful to get an example. I have an old(er) script with the >> following task - takes a string I copy-pasted and wich always has the

Re: re beginner

2006-06-04 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : >>strings = islice(data2, 0, len(data), 2) >>numbers = islice(data2, 1, len(data), 2) > > > This probably has to be: > > strings = islice(data2, 0, len(data2), 2) > numbers = islice(data2, 1, len(data2), 2) try with islice(data2, 0, None, 2) -- http://mail.python.or

Re: re beginner

2006-06-04 Thread Bruno Desthuilliers
SuperHik a écrit : > hi all, > > I'm trying to understand regex for the first time, and it would be very > helpful to get an example. I have an old(er) script with the following > task - takes a string I copy-pasted and wich always has the same format: > > >>> print stuff > Yellow hat2

Re: re beginner

2006-06-04 Thread bearophileHUGS
> strings = islice(data2, 0, len(data), 2) > numbers = islice(data2, 1, len(data), 2) This probably has to be: strings = islice(data2, 0, len(data2), 2) numbers = islice(data2, 1, len(data2), 2) Sorry, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: re beginner

2006-06-04 Thread faulkner
you could write a function which takes a match object and modifies d, pass the function to re.sub, and ignore what re.sub returns. # untested code d = {} def record(match): s = match.string[match.start() : match.end()] i = s.index('\t') print s, i# debugging d[s[:i]] = int(s[i+

Re: re beginner

2006-06-04 Thread bearophileHUGS
SuperHik wrote: > I was wondering is there a better way to do it using re module? > perheps even avoiding this for loop? This is a way to do the same thing without REs: data = 'Yellow hat\t2\tBlue shirt\t1\nWhite socks\t4\tGreen pants\t1\nBlue bag\t4\tNice perfume\t3\nWrist watch\t7\tMobile phone