linux - List of empty string returns non-zero length in python -
this question has answer here:
- remove empty strings list of strings 12 answers
i have list of strings returned after command execution, split on '\n'.
listname = output.decode('utf8').rstrip().split('\n') when print using print(listname), get
[''] clearly it's list containing empty string
because of getting len(listname) 1.
how remove empty string
i think looking for:
filter(none,output.decode('utf8').rstrip().split('\n')) in details:
>>> filter(none, ["ford", "nissan", ""]) ['ford', 'nissan'] p.s. in python 3+ filter returns iterator, use list(filter(..)).
Comments
Post a Comment