Friday, 14 April 2017

python - How to remove all elements of five from a list

My code for this returns 'None'.
In case my question is not clear if i take the list [1 , 3 , 4 , 5 ,5 , 7], I want the list [1 , 3 , 4 , 7] to be returned. My code is as follows:



print("This program takes a list of 5 items and removes all elements of 5: ")

list4 = []
list4.append(input("Please enter item 1:"))
list4.append(input('Please enter item 2:'))

list4.append(input('Please enter item 3:'))
list4.append(input('Please enter item 4:'))
list4.append(input('Please enter item 5:'))
def remove_five():
while 5 in list4:
list4.remove(5)
print(remove_five())

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...