Sometimes .remove fails
so, this is a piece of code that drafts every player in the premier league (association football), in the form of 26 player teams (starting 11 and 15 players as backups). it is coded in python because that is the language i am most fluent in due to GCSE's. sometimes within the code, the ".remove" doesn't work, this has only been documented once, though so i'm wondering if it is just a thing i have to accept as an anomaly or if i have to fix something. much appreciate any help, thanks.
I've always seen
.remove as very finicky, if it continues to not work I usually just end up replacing it with this:
itemToFind = "a thing" for index, item in enumerate(testList): if item == itemToFind: del testList[index]
or this as a shorthand
# This uses a generator VVVVVVVVVVVVVVVVVVVVVVVVVVVV testList = [item for item in testList if item != itemToFind]
where exactly does .remove not work? Also, to make your code easier to read you could probably do
@LukeWright the only recorded case i have seen is in the subroutine for burnley, it does seem to indicate randomness though, seeing as all the subroutines are almost identical. i had thought of using the code you suggested, but seeing as i need to use the data that is randomised at a later date i wasnt sure if it would work, it also might make it harder for people that have little to no skill in the language to understand seeing as this was made for a discord server.