Question about regular expression

Denis McMahon denismfmcmahon at gmail.com
Thu Oct 1 17:31:58 EDT 2015


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.

What happens if there's more whitespace than you allow for preceding a 
'(' or following a ',', or if there's whitespace following '('?

-- 
Denis McMahon, denismfmcmahon at gmail.com



More information about the Python-list mailing list