I have a data table in a python list and the data looks like this:
[
{Artist='Madonna', album='Ray of Light', title='Substitute for love'},
{Artist='Madonna', album='Ray of Light', title='Frozen'},
{Artist='Madonna', album='Something to remember', title='You'll see'},
{Artist='Madonna', album='Bedtime stories', title='Secret'},
{Artist='U2', album='The Joshua Tree', title='Where the streets have no name'},
{Artist='U2', album='The Joshua Tree', title='I still haven'ts found...'},
{Artist='U2', album='The Joshua Tree', title='With or without you'},
{Artist='U2', album='Acthung Baby', title='One'},
{Artist='U2', album='Acthung Baby', title='Until the end of the world'}
]
and I want to put it into a tree view (specifically, a QTreeWidget), so that it looks like this:
- Madonna
- Ray of Light
- Substitute for love
- Frozen
- Something to remember
- You’ll see
- Bedtime stories
- Secret
- Ray of Light
- U2
- The Joshua Tree
- Where the streets..
- I still haven’t…
- Achtung baby
- One
- Until the end of..
- The Joshua Tree
I don’t know how to code it in this way: I think of nested loops but I can’t find a solution. Has anyone worked on a solution for this query, in any language please?
If not the code, I’ll need the logic. Then anyone could implement it using their own programming language.
You can turn the list of records into a nested dictionary using nested defaultdicts.
Once you have the data in this form, it’s easy to print it in the format you require.
Here’s a straightforward approach for your example: