How to remove empty entries during string split in Python

1 Answer

0 votes
def string_split_with_no_empty_entries(s, delimiter):
    return list(filter(str.strip, s.split(delimiter)))

s = "python   c#     java    sql"
a_list = string_split_with_no_empty_entries(s, " ")

print(a_list)

'''
run:

['python', 'c#', 'java', 'sql']

'''

 



answered Oct 23, 2017 by avibootz
...