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
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"""
Although there is nothing syntactically wrong with this code, it is hard to read and can be simplified to a dict comprehension. Using dictionary comprehension is more performant since there is no need to create a transient list.
mapping = dict([(num, str(num)) for num in my_magic_nums])
mapping = {num: str(num) for num in my_magic_nums}