Skip to content

consider using sort(key=...) function #573

@sgratzl

Description

@sgratzl

it looks quite difficult how the sorting is handled:

sorting_fields = "data_source signal time_type geo_type".split()
sortable_fields_fn = lambda x: [(field, x[field]) for field in sorting_fields]
prepended_sortables_fn = lambda x: sortable_fields_fn(x) + list(x.items())
tuple_representation = list(map(prepended_sortables_fn, meta))
tuple_representation.sort()
meta = list(map(dict, tuple_representation)) # back to dict form

can't the key function as in .sort(key=lambda x: (x['data_source'], x['signal'], x['time_type'], x['geo_type'])) be used instead?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions