-2

if i print my list called text:

print(text)

the return will show something like

[['this', 'example', '',], ['a','b','']]

How do i remove the empty strings from here?

  • Possible duplicate of [How to remove an element from a list by index in Python?](https://stackoverflow.com/questions/627435/how-to-remove-an-element-from-a-list-by-index-in-python) – Alessandro Da Rugna Nov 26 '17 at 13:56

1 Answers1

2

With a list comprehension:

text = [['this', 'example', '',], ['a','b','']]
print([[string for string in sublist if string] for sublist in text])
#  [['this', 'example'], ['a', 'b']]
DeepSpace
  • 78,697
  • 11
  • 109
  • 154