This is the output after some processing. I want to remove the null/empty values from the array.
['HOST1', '6667', 'CHANNAME1', '', 'CHANNAME2', '', '', 'HOST2', '6667', 'CHANNAME3', '', '', '']
This is the output after some processing. I want to remove the null/empty values from the array.
['HOST1', '6667', 'CHANNAME1', '', 'CHANNAME2', '', '', 'HOST2', '6667', 'CHANNAME3', '', '', '']
[x for x in a if x != '']
You can use this to filter the ''
EDIT considering saybyasachi's suggestion. Using the fact that all elements are strings, a more pythonic way to approach would be:
[x for x in a if x]
Like this, which retains any item with any sort of worthwhile value:
[item for item in array_name if item]