Question about regular expression

gal kauffman gal.kauffman at gmail.com
Thu Oct 1 17:50:43 EDT 2015


On Oct 2, 2015 12:35 AM, "Denis McMahon" <denismfmcmahon at gmail.com> wrote:
>
> On Thu, 01 Oct 2015 01:48:03 -0700, gal kauffman wrote:
>
> > items = s.replace(' (', '(').replace(', ',',').split()
> >
> > items_dict = dict()
> > for item in items:
> >     if '(' not in item:
> >         item += '(0,0)'
> >     if ',' not in item:
> >         item = item.replace(')', ',0)')
> >
> >     name, raw_data = item.split('(') data_tuple = tuple((int(v) for v in
> > raw_data.replace(')','').split(',')))
> >
> >     items_dict[name] = data_tuple
>
> Please don't top post.
Sorry  :(
>
> What happens if there's more whitespace than you allow for preceding a
> '(' or following a ',', or if there's whitespace following '('?
My code won't work. Even worse then that, it will return a dict as if
everything is OK, but the dict will have weird keys and values.
But I didn't try to make it work for every possible input. It works for the
conventions defined.

If I wanted to accept a wider range of values, I would write another
program that applies the conventions on the input, and chain it with the
current code.
>
> --
> Denis McMahon, denismfmcmahon at gmail.com
> --
> https://mail.python.org/mailman/listinfo/python-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20151001/872e882d/attachment.html>


More information about the Python-list mailing list