Skip to content

Commit 8c5b3a8

Browse files
committed
Added logic to sort fully numeric dictionary keys numerically and separately from alphanumeric ones
1 parent 9954b76 commit 8c5b3a8

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/murfey/cli/generate_config.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,18 @@ def construct_dict(
188188
continue
189189

190190
# Sort keys if set
191-
dct = {key: dct[key] for key in sorted(dct.keys())} if sort_keys else dct
191+
dct = (
192+
{
193+
key: dct[key]
194+
for key in sorted(
195+
dct.keys(),
196+
# Sort numeric keys as numerals and alphanumeric keys alphabetically
197+
key=(lambda k: (0, float(k) if str(k).isdigit() else (1, str(k)))),
198+
)
199+
}
200+
if sort_keys
201+
else dct
202+
)
192203
return dct
193204

194205

0 commit comments

Comments
 (0)