ndd.py

Created by wperez274

Created on September 09, 2023

1.36 KB


# 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
for i, sub_list in enumerate(level_1):
    for j, sub_sub_list in enumerate(sub_list):
        if isinstance(sub_sub_list[-1], tuple) and sub_sub_list[-1] in color_dict:
            level_1[i][j][-1] = color_dict[sub_sub_list[-1]]

# Print the modified nested list
for i, sub_list in enumerate(level_1):
    print(f"# area={i}")
    for sub_sub_list in sub_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:

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.