drop items based on condition in python list of list code example
Example: python filter remove from list
# Say you have the array ['', 'foo', '.', 'bar', 'foo', '', 'bar']
# and you want to remove the empty characters and periods. You do:
tokens = filter(isImportant, array)
for token in tokens:
print(token)
# prints:
# > foo
# > bar
# > foo
# > bar
def isImportant(token):
if token == '' or token == '.':
return False
return True