hello, I have multiple song details (title, lyrics, link, etc.), and I want to store them in a dictionary using song_code as the key. Each song_code should have multiple titles, lyrics, and links stored in a list.
For example, I have the following data:
song_code: AG001
song_title: Amazing Grace
song_lyric: Amazing grace! how sweet the sound...
play_link: https://play.example.com/ag001
Later, I might add another title and lyric , playlink for the same song_code, so the structure should look like this in a dictionary:
{
"AG001": {
"titles": ["Amazing Grace", "Amazing Grace (Cover by John)"],
"lyrics": ["Amazing grace! how sweet the sound...", "Amazing grace! how sweet the sound... (cover version)"],
"play_link": ["https://play.example.com/ag001", "https://play.example.com/ag001-cover"]
}
}
How can I store this structure in a dictionary and save it in TinyDB ? I also want to display all song titles in a ListView.Thanks in advance!
{
"ag001":[
{
title:a title,
lyrics:amazing grace,
play_link: some real link
},
{
title:title2,
lyrics:amazing grace2,
play_link: some real link2
},
...
],
"ag002":[
{
title:a title,
lyrics:amazing grace,
play_link: some real link
},
{
title:title2,
lyrics:amazing grace2,
play_link: some real link2
},
...
]
}
If the combination title/code is unique, you could use that as a TinyDB tag (text JOIN of the two parts with a '/' or '|' between them and either store the remaining attributes under that tag as a dictionary, or use separate Namespaces for each attribute (link, lyrics,...) with the same compound title/code tag.
I like using this TinyDb Taglist to feed a ListView. If you want to get fancy, split the tags into major and detail text parts of your ListView Elements in a loop over your taglist.