pnijhara / gitsome

Consider using a dictionary comprehension PYL-R1717
Performance
Major
4 years ago4 years old
Consider using a dictionary comprehension
119    # parse the css. reverted from dictionary compehension in order to support older pythons
120    elements =  [x.split('{') for x in data.split('}') if '{' in x.strip()]
121    try:
122        elements = dict([(a.strip(), dumb_property_dict(b)) for a, b in elements])123    except ValueError:
124        elements = {} # not that important
125
Consider using a dictionary comprehension
105
106def dumb_property_dict(style):
107    """returns a hash of css attributes"""
108    return dict([(x.strip(), y.strip()) for x, y in [z.split(':', 1) for z in style.split(';') if ':' in z]]);109
110def dumb_css_parser(data):
111    """returns a hash of css selectors, each of which contains a hash of css attributes"""