I am writing a def function that will take in input to a list. First, it will detect if there is the same value in that list, if yes, it will put it to another list, if no, it will put it in the first list. The code is something like this:
uniqueList = [] leftover = [] def addToList(number): if any(uniqueList.count(number) > 0 for number in UniqueList): leftover.append(number) return leftover else: uniqueList.append(number) return uniqueList
The problem is when I run it, the number input doesn't seem to be saved to the list, for example, the first input is '20', then the output is [20] for the uniqueList and [ ] for leftover. But when I input '20' again, the output is still [20] for the uniqueList and [ ] for leftover. Why is this happening?
https://stackoverflow.com/questions/65444595/how-to-return-the-local-value-of-a-function-to-my-global-list-python December 25, 2020 at 09:50AM
没有评论:
发表评论