Oct-28-2017, 03:09 AM
I am trying to make a function that returns a new list where each item that appears an odd number of times in l is removed
For example,
A list like this:
['1', '2','2','4', '5','1','6','2', '6']
Becomes:
['1','2','2','1','6','6']
(doesn't matter what order)
I am trying to use the count method for lists and to determine the number of occurrences for each item in the list and append it to a new one but I can't seem to make it work
Here is what I have so far:
For example,
A list like this:
['1', '2','2','4', '5','1','6','2', '6']
Becomes:
['1','2','2','1','6','6']
(doesn't matter what order)
I am trying to use the count method for lists and to determine the number of occurrences for each item in the list and append it to a new one but I can't seem to make it work
Here is what I have so far:
def clean_up_board(l): playable_board=[] for i in range(len(l)): num_of_occ=l.count(i) if num_of_occ%2==0: playable_board.append(i) return playable_board