171 )
172
173 if isinstance(attrs['headers'], dict):
174 attrs['headers'] = dict([[key, str(value)] for key, value in attrs['headers'].items()])175
176 return attrs
177
9 return []
10 # value = list(filter(lambda x: x != '', value.split(',')))
11 value = value.split(',')
12 return dict([['param_{}'.format(i), x] for i, x in enumerate(value)])13
14 def to_representation_item(self, value):
15 return list(value)
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}