0

I'm new to python so if this is obvious break it to me as nicely as possible. Basically, every time I use list.remove() it removes it for the current use of the program but readds it whenever I reopen it, or I guess it never deletes it in the first place. I was wondering if there was a way to permanently alter the list and remove it from the code itself using only the program and not having to do it manually.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • The answer is `del` statement. No, `remove()` does not re-add. Your code seems to have a logic bug. For example, you cannot use `remove()` while iterating over a list – OneCricketeer Apr 15 '23 at 04:59
  • 1
    "it removes it for the current use of the program but readds it whenever I reopen it" - the list in your new run is a different list. `list.remove` isn't going to edit your program's source code so the program builds a smaller list the next time it runs. – user2357112 Apr 15 '23 at 05:02
  • What you're trying to do is a job for separate data files, not self-modifying code. You can read and write to a data file to preserve data across runs. – user2357112 Apr 15 '23 at 05:04
  • 2
    "it removes it for the current use of the program" - yes, that's how programs work. The program is a list of instructions that will be followed the same way every time. If you want to remember information between two runs of the program, you need to save and reload that information, for example by using a *file* on your computer's hard drive (or SSD), and you need to write code that creates and *formats* raw data to write to the file and can read and *parse* (interpret) it again later. This has nothing to do with lists. – Karl Knechtel Apr 15 '23 at 05:08

0 Answers0