python filter remove from list

Solutions on MaxInterview for python filter remove from list by the best coders in the world

showing results for - "python filter remove from list"
Davina
30 Aug 2020
1# Say you have the array ['', 'foo', '.', 'bar', 'foo', '', 'bar']
2# and you want to remove the empty characters and periods. You do:
3  
4tokens = filter(isImportant, array) 
5
6for token in tokens:
7  print(token)
8  
9# prints:
10# > foo
11# > bar
12# > foo
13# > bar
14
15def isImportant(token):
16	if token == '' or token == '.':
17      return False
18    return True
19
20