# Define a dictionary for color values
color_dict={(255,125,99):"light salmon",(223,78,252):"dark orchid",(220,102,200):"orchid",(8,102,200):"blue",(45,65,"SH"):"black",(183,16,235):"purple","SH":"black","SW":"black"}# Given nested list
level_1=[# area=0= home
[[0,208,78,14,(176,157,217)],[0,199,14,8,(144,46,229)],[126,200,32,22,(51,18,23)],[177,209,10,12,(39,41,41)]],# area=1
[[0,64,148,170,"black"],[105,127,114,136,"black"],[162,181,28,40,"black"],[30,43,28,28,"black"],[51,25,54,64,"black"],[37,184,42,40,(189,25,51)],[13,100,24,28,(45,138,186)]],# area=2
[[75,178,154,44,"black"],[99,145,110,44,"black"],[114,145,86,64,"red"],[236,85,86,64,"red"],[50,16,22,32,(153,126,88)]],# ... (other nested lists)
]# Loop through the nested lists and replace color values with color names
fori,sub_listinenumerate(level_1):forj,sub_sub_listinenumerate(sub_list):ifisinstance(sub_sub_list[-1],tuple)andsub_sub_list[-1]incolor_dict:level_1[i][j][-1]=color_dict[sub_sub_list[-1]]# Print the modified nested list
fori,sub_listinenumerate(level_1):print(f"# area={i}")forsub_sub_listinsub_list:print(sub_sub_list)
During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:
Ensure the proper functioning of the site (essential cookies); and
Track your browsing to send you personalized communications if you have created a professional account on the site and can be contacted (audience measurement cookies).
With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.