Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Convert A Dictionary Into A Sorted List In Python

Code

genres = {
	"Junk": [1],
	"Chill": [2],
	"Dance": [3],
	"Jass": [4], 
	"A": [7],
	"B": [1],
	'a': [3],
	'c': [2], 
	"Adf": [],
	"Aeee": [],
	"aeeed": [],
	"Aerer": []
}

items = [{"id": f, "data": genres[f]} for f in sorted(genres.keys(), key=lambda x: x.lower())]

print(items)