Python Forum
How to add list to dictionary?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to add list to dictionary?
#1
Hey, how would I add a nested list to a dictionary based on the dictionary key and list element. Say the dictionary represented the columns of a dataset and the list represented the rows, how can I add the corresponding row to column.

This is the dictionary:

{'NS BEAM': '', 'NS BEAM GALV': '', 'NS FRAME': '', 'NS FRAME GALV': '', 'NS FRAME 3-POST': '', 'NS FRAME CUT PINE': '', 'NS FRAME CUT': '', 'NS PURCHASED': '', 'NS FRAME CUT BEAM': '', 'NS FRAME CUT VRACK': '', 'STANDARD': '', 'STANDARD BEAM': '', 'STANDARD FRAME': '', 'STANDARD FRAME GALV': '', 'STANDARD GALV': '', 'STANDARD PURCHASED': '', 'STANDARD BEAM GALV': ''}
This is the nested list:

[['3623T', '3320BG', '4009HS', '4067G', '4051H', '4154H', '3108H', '3806A', '3200H', '4150T', '3997GH', '3208BT', '4009H', '4062GVN', '3529GG', '3589', '3413BG'], ['3625T', '3347BG', '4009TS', '3065HG', '4050H', '4155H', '3031TS', '3895T', '3318H', '4149T', '3995GH', '3352BH', '4009T', '4113GVN', '3735G', '3242', '3413G'], ['3442BH', '3352BG', '4014HS', '3018G', '4052H', '4147H', '3031TS', '3894H', '3318T', '4152T', '3926H', '3352BT', '4014H', '4064G', '3522GHD', '3590', ''], ['3319BH', '3383BG', '4013HS', '3108G', '4052T', '4146H', '3033T', '3894T', '3319H', '4151T', '3924H', '3201H', '4014T', '', '3995G', '3579H', ''], ['3320BH', '3320G', '4013HT', '3120G', '4058T', '', '', '3925H', '3202BH', '4158T', '3923H', '3201T', '4013H', '', '3998G', 'N3605BT', ''], ['3320BT', '3347G', '4039HS', '3031GN', '4054T', '', '', '3555H', '3202H', '3557T', '3739HD', '3203H', '4013T', '', '3603FG', '301', ''], ['3347BH', '3348G', '4039TS', '4065G', '4060T', '', '', '3994G', '3202BT', '4152TS', '3735HD', '3203T', '3019H', '', '3604FG', '3579HS', ''], ['3347BT', '3350G', '4040HS', '4114GVN', '4061T', '', '', '3980G', '3202T', '4153TS', '3924T', '3206H', '3005H', '', '3606FG', 'N3604B', ''], ['3442BCH', '3352G', '4069TS', '', '4085T', '', '', '3897T', '', '4153T', '3923T', '3206T', '3005T', '', '3605FG', 'N3605B', ''], ['3348BH', '3383G', '4066HS', '', '4086T', '', '', '3898T', '', '4159H', '3926T', '3207H', '4039H', '', '3609FG', '', ''], ['3348BT', '3382G', '4073TS', '', '4085TS', '', '', '3553H', '', '', '3524G', '3207T', '4039T', '', '3609FG', '', ''], ['3442BDH', '3416G', '4073HS', '', '3188', '', '', '3553T', '', '', '', '3212H', '4068H', '', '3922', '', ''], ['3350BH', '3410G', '3078TS', '', '', '', '', '3550H', '', '', '', '3208H', '4040T', '', '3586', '', ''], ['3350BT', '3394G', '4099TS', '', '', '', '', 'N3603B', '', '', '', '3208T', '4040H', '', '', '', ''], ['3454BH', '3348BG', '4062HS', '', '', '', '', 'N3603BT', '', '', '', '3320H', '3035T', '', '', '', ''], ['3454BT', '3380G', '4062TS', '', '', '', '', 'N3604BT', '', '', '', '3320T', '4070T', '', '', '', ''], ['3383BH', '', '4103HS', '', '', '', '', 'N3606B', '', '', '', '3347H', '4069H', '', '', '', ''], ['3383BT', '', '4103TS', '', '', '', '', '3556T', '', '', '', '3347T', '4069T', '', '', '', ''], ['3382BH', '', '4129HS', '', '', '', '', '3806F', '', '', '', '3348H', '4066H', '', '', '', ''], ['3382BT', '', '4129TS', '', '', '', '', '3806', '', '', '', '3348T', '4066T', '', '', '', ''], ['3416BH', '', '4067HS', '', '', '', '', '3806G', '', '', '', '3352H', '4073H', '', '', '', ''], ['3420BH', '', '4133HS', '', '', '', '', '3925', '', '', '', '3352T', '4073T', '', '', '', ''], ['3437BH', '', '4133TS', '', '', '', '', '', '', '', '', '3383H', '4063H', '', '', '', ''], ['3438BH', '', '4065TS', '', '', '', '', '', '', '', '', '3383T', '3079H', '', '', '', ''], ['3438BT', '', '3031HS', '', '', '', '', '', '', '', '', '3382H', '3079T', '', '', '', ''], ['3442CH', '', '4063TS', '', '', '', '', '', '', '', '', '3382T', '3065H', '', '', '', ''], ['3442CT', '', '3018HS', '', '', '', '', '', '', '', '', '3420H', '3065T', '', '', '', ''], ['3349T', '', '3078HS', '', '', '', '', '', '', '', '', '3420T', '4074H', '', '', '', ''], ['3350H', '', '3125TS', '', '', '', '', '', '', '', '', '3201BH', '4099H', '', '', '', ''], ['3350T', '', '', '', '', '', '', '', '', '', '', '3201BT', '4099T', '', '', '', ''], ['3454H', '', '', '', '', '', '', '', '', '', '', '3203BH', '4062H', '', '', '', ''], ['3454T', '', '', '', '', '', '', '', '', '', '', '3203BT', '4062T', '', '', '', ''], ['3391H', '', '', '', '', '', '', '', '', '', '', '3206BH', '4103H', '', '', '', ''], ['3391T', '', '', '', '', '', '', '', '', '', '', '3206BT', '4103T', '', '', '', ''], ['3378H', '', '', '', '', '', '', '', '', '', '', '3207BH', '4064H', '', '', '', ''], ['3378T', '', '', '', '', '', '', '', '', '', '', '3207BT', '3109H', '', '', '', ''], ['', '', '', '', '', '', '', '', '', '', '', '3212BH', '3109T', '', '', '', ''], ['', '', '', '', '', '', '', '', '', '', '', '3212BT', '3095H', '', '', '', ''], ['', '', '', '', '', '', '', '', '', '', '', '3208BH', '3095T', '', '', '', ''], ['', '', '', '', '', '', '', '', '', '', '', '3308T', '4113T', '', '', '', ''], ['', '', '', '', '', '', '', '', '', '', '', '3308H', '4129H', '', '', '', ''], ['', '', '', '', '', '', '', '', '', '', '', '', '4129T', '', '', '', ''], ['', '', '', '', '', '', '', '', '', '', '', '', '4067H', '', '', '', ''], ['', '', '', '', '', '', '', '', '', '', '', '', '4067T', '', '', '', ''], ['', '', '', '', '', '', '', '', '', '', '', '', '4133H', '', '', '', ''], ['', '', '', '', '', '', '', '', '', '', '', '', '4133T', '', '', '', ''], ['', '', '', '', '', '', '', '', '', '', '', '', '4065H', '', '', '', ''], ['', '', '', '', '', '', '', '', '', '', '', '', '4065T', '', '', '', ''], ['', '', '', '', '', '', '', '', '', '', '', '', '3125T', '', '', '', ''], ['', '', '', '', '', '', '', '', '', '', '', '', '4063T', '', '', '', ''], ['', '', '', '', '', '', '', '', '', '', '', '', '4064T', '', '', '', ''], ['', '', '', '', '', '', '', '', '', '', '', '', '4112T', '', '', '', ''], ['', '', '', '', '', '', '', '', '', '', '', '', '4117T', '', '', '', ''], ['', '', '', '', '', '', '', '', '', '', '', '', '4075H', '', '', '', ''], ['', '', '', '', '', '', '', '', '', '', '', '', '4041H', '', '', '', ''], ['', '', '', '', '', '', '', '', '', '', '', '', '4041T', '', '', '', ''], ['', '', '', '', '', '', '', '', '', '', '', '', '3127T', '', '', '', ''], ['', '', '', '', '', '', '', '', '', '', '', '', '4075T', '', '', '', ''], ['', '', '', '', '', '', '', '', '', '', '', '', '4070H', '', '', '', ''], ['', '', '', '', '', '', '', '', '', '', '', '', '4102T', '', '', '', '']]
Reply


Messages In This Thread
How to add list to dictionary? - by Kull_Khan - Apr-03-2023, 07:08 PM
RE: How to add list to dictionary? - by menator01 - Apr-03-2023, 07:31 PM
RE: How to add list to dictionary? - by deanhystad - Apr-03-2023, 09:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sort a list of dictionaries by the only dictionary key Calab 2 644 Apr-29-2024, 04:38 PM
Last Post: Calab
  Dictionary in a list bashage 2 603 Dec-27-2023, 04:04 PM
Last Post: deanhystad
  filtering a list of dictionary as per given criteria jss 5 753 Dec-23-2023, 08:47 AM
Last Post: Gribouillis
  check if element is in a list in a dictionary value ambrozote 4 2,027 May-11-2022, 06:05 PM
Last Post: deanhystad
  Dictionary from a list failed, help needed leoahum 7 2,049 Apr-28-2022, 06:59 AM
Last Post: buran
  how to assign items from a list to a dictionary CompleteNewb 3 1,623 Mar-19-2022, 01:25 AM
Last Post: deanhystad
  Python, how to manage multiple data in list or dictionary with calculations and FIFO Mikeardy 8 2,694 Dec-31-2021, 07:47 AM
Last Post: Mikeardy
  Class-Aggregation and creating a list/dictionary IoannisDem 1 1,952 Oct-03-2021, 05:16 PM
Last Post: Yoriz
  Python dictionary with values as list to CSV Sritej26 4 3,076 Mar-27-2021, 05:53 PM
Last Post: Sritej26
  convert List with dictionaries to a single dictionary iamaghost 3 2,892 Jan-22-2021, 03:56 PM
Last Post: iamaghost

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020