remove list item python by condition code example
Example 1: python remove by index
a = [0, 1, 2, 3, 4, 5]
el = a.pop(2)
Example 2: 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