[Python] Python - What Causes a List Index to be Out Of Range

Discussão em 'Python' iniciado por Stack, Junho 18, 2025.

  1. Stack

    Stack Membro Participativo

    I am not sure why I am getting the list out of range error. Everything seems to be fine. I even individually checked the index value.

    Error is at if pairs[j] == all_list[ii][jj]:


    list_1 = ['Wire#1', 'Wire#3', 'Wire#4']
    list_2 = ['Wire#5', 'Wire#8', 'Wire#13']
    all_list = [list_1, list_2]

    pairs = [
    ["Wire#3","Wire#13"],
    ["Wire#4","Wire#8"],
    ["Wire#1","Wire#5"],
    ]

    new_wire_list = []
    for i in range(0, len(pairs)):
    if len(pairs) > 1:
    new_text = ""
    for char in range(0, len(pairs)):
    new_text += pairs[char] + "_"
    new_wire_list.append(new_text)
    for j in range(0, len(pairs)):
    for ii in range(0, len(all_list)):
    for jj in range(0, len(all_list[ii])):
    if pairs[j] == all_list[ii][jj]:
    index_of = all_list[ii][jj].index(pairs[j])
    all_list[ii].pop(index_of)
    print(all_list)

    Continue reading...

Compartilhe esta Página