'Have a list of passwords in a text file and trying to delete on password from the file

This is what I have, it seems to be just deleting random parts from the text file

any help would be great thanks!

def deletepass(x):
og ="Login.txt"
temp ="Temp.txt"
Pass_to_delete = x
with open(og,"r") as y:
    with open(temp,"w") as z:
        for line in y:
            for word in Pass_to_delete:
                line = line.replace(word, "")
            z.write(line)
            os.replace("Temp.txt","Login.txt")
print("Your password has been deleted")
menu()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source