How to return an empty list in python
How to return an empty list in python
Here, I took the liberty to tidy up the code.
def start(): # dont use the name input()
nextRound = [Dad, Mom]
maleNames = [son, James, Mick, Dad]
a = int(input(Enter a number please))
if a == 1:
nextRound, maleNames = ErrorInput(1, nextRound, maleNames) # if you want nextRound, maleNames to be [] you have to assign it to them
print(nextRound, maleNames)
def ErrorInput(error, namelist, round):
error_codes = {1: ERROR: You have entered a number above what is impossible to score, 2: ERROR: You Have entered a score meaning both players win,3: ERROR: You have entered a score meaning neither of the two players win, 4: ERROR: You have entered a negative number, this is impossible} # too many ifs makes one wonder if a dictionary is the way to go
print(error_codes.get(error, Unknown Error))
return([], []) # return the empty lists.
start()
Not sure why you go to such lengths to just get [], []
but whatever floats your boat.
Take a look at the notes on the code to get a better feeling of why I made the changes.
As per the comment above, i dont follow your code. But to iteratively empty a list try:
while len(maleNames) !=0:
popped = maleNames.pop()
print(Popped value: , popped, tNew list: , maleNames)
How to return an empty list in python
Use namelist.clear()
to clear a list