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)
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
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.
>
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
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
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
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):
>>
"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
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'
"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
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
[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
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
> 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
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+
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
16 matches
Mail list logo