Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8883127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:44:28+00:00 2026-06-14T20:44:28+00:00

I have a data table in a python list and the data looks like

  • 0

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
  • U2
    • The Joshua Tree
      • Where the streets..
      • I still haven’t…
    • Achtung baby
      • One
      • Until the end of..

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:44:29+00:00Added an answer on June 14, 2026 at 8:44 pm

    You can turn the list of records into a nested dictionary using nested defaultdicts.

    from collections import defaultdict
    
    data = [ {'Artist':'Madonna', 'album':'Ray of Light', 'title':'Substitute for love'},
             ....
             {'Artist':'U2', 'album':'Acthung Baby', 'title':'Until the end of the world'}
          ]   
    
    tree_data = defaultdict(lambda: defaultdict(list))
    
    for d in data:
        tree_data[d['Artist']][d['album']].append(d['title'])
    

    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:

    for artist in tree_data.keys():
        print(artist)
        for album, titles in tree_data[artist].iteritems():
            print("\t" + album)
            for title in titles:
                print ("\t\t" + title)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data.table object like this one library(data.table) a <- structure(list(PERMNO = c(10006L,
I have a python list that looks like this example: [[' 1', ' 200',
I have a data.table object similar to this one library(data.table) c <- data.table(CO =
To generate a Table of Content, I have these data available in a Python
I have a table that seems like this: +-----+-----------+------------+ | id | value |
I have a list of tuples in Python that I would like to output
I have data table containing one column as FilePath. FilePath D:\New folder\link.txt D:\New folder\SharepointMigration(Work
I have a data table with many rows and columns. How can I display
I have the data table from the jquery plugin dataTables (http://datatables.net/) that I want
I have a data table which already has some values, plus it is getting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.