Dec-07-2018, 04:21 AM
I want to convert a dict of audio metadata into an ordered dict, sorted by it's nested values (such as values of keys 'artist' or 'track'). What would be the fastest way to achieve this?
The database is organized like this:
The database is organized like this:
#!/usr/bin/python3 from collections import OrderedDict db = \ { "/data/Music/Daft Punk/Tron_ Legacy (Cd1)/1-17 Disc Wars.mp3": { "duration": "00:04:11", "artist": "Daft Punk", "album": "Tron: Legacy (Cd1)", "track": "17", "title": "Disc Wars" }, "/data/Music/Keith Kouna/Les ann\u00e9es monsieur/07 - Godichons.mp3": { "duration": "00:05:09", "artist": "Keith Kouna", "album": "Les ann\u00e9es monsieur", "track": "7", "title": "Godichons" }, "/data/Music/Daft Punk/Tron_ Legacy (Cd1)/1-07 Rinzler.mp3": { "duration": "00:02:17", "artist": "Daft Punk", "album": "Tron: Legacy (Cd1)", "track": "07", "title": "Rinzler" }, "/data/Music/Keith Kouna/Les ann\u00e9es monsieur/10 - Le Tape.mp3": { "duration": "00:06:06", "artist": "Keith Kouna", "album": "Les ann\u00e9es monsieur", "track": "10", "title": "Le Tape" }, "/data/Music/Keith Kouna/Les ann\u00e9es monsieur/09 - L'or.mp3": { "duration": "00:05:05", "artist": "Keith Kouna", "album": "Les ann\u00e9es monsieur", "track": "9", "title": "L'or" } } db = OrderedDict(sorted(db.items(), key=lambda t: t[0])) for key in db: print(key)