Last active
April 25, 2022 17:15
-
-
Save allynt/ae775119c6118ff512c280325b5daf51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
# must be zero-based | |
CATEGORIES_ORDER = { | |
"SSSI": 0, | |
"SAC": 1, | |
"SPA": 2, | |
"RAMSAR": 3, | |
"GCR": 4, | |
"LNR": 5, | |
"CNTRYPK": 6 | |
} | |
category_key = lambda area: area["category"] | |
sorted_grouped_areas = [] | |
tmp_areas = [ | |
(key, list(group)) | |
for key, group in itertools.groupby(sorted(xx, key=category_key), key=category_key) | |
] | |
tmp_areas.sort(key=lambda grouped_area: CATEGORIES.get(grouped_area[0], len(CATEGORIES))) | |
for key, group in tmp_areas: | |
sorted_grouped_areas += group | |
#for key, group in itertools.groupby(sorted(processed_data["areas"], key=category_key), key=category_key): | |
# sorted_areas.insert(CATEGORIES_ORDER.get(key, len(sorted_areas)), list(group)) | |
#sorted_areas = itertools.chain.from_iterable(sorted_areas) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment