Answers for "python filter remove from list"

0

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
Posted by: Guest on July-15-2020

Code answers related to "python filter remove from list"

Python Answers by Framework

Browse Popular Code Answers by Language