Home > Software engineering >  how i can give a good struture to my defaultdict
how i can give a good struture to my defaultdict

Time:02-24

I have a defaultdict on my views.py: output:

defaultdict(<class 'list'>, {'List of tubes': ['2324', '98', '7654', 'List of auto:': [147, 10048, 1009, 10050, 10, 1647, 10648, 649, 1005]})

how i can give a better structure to my defaultdict ?

like this :

list of tube :
2324
98
7654
list of auto :
147
10048
1009
10050 
10
1647
10648
649
1005

CodePudding user response:

d = defaultdict(list)
d['List of tubes'] = ['2324', '98', '7654']
d['List of auto'] = [147, 10048, 1009, 10050, 10, 1647, 10648, 649, 1005]   

for key, value in d.items():
        print(key)
        for i in value:
            print(i)
  • Related