[Python] How can I overwrite and existing list with an updated one? [duplicate]

Discussão em 'Python' iniciado por Stack, Março 31, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to write a program that will sort a list alphabetically. I would like to be able to change items from that list, but I have issues overwriting the original list with an updated one.

    This what I have right now:

    def add_items():
    add_list = input("Please enter your additional items separated by space: ")
    list_to_add = add_list.split(" ")
    new_list = finished_list + list_to_add
    updated_list = sorted(new_list)
    finished_list = updated_list[:]


    On the last line, I get an error that says UnboundLocalError: local variable 'finished_list' referenced before assignment.

    What is wrong, and how do I fix it?

    Continue reading...

Compartilhe esta Página