Python3系 配列の中の空文字を一括削除

組み込み関数filter()と無名関数lambda(ラムダ式)を使い一括で削除する

カンマ区切りのデータで空文字があったときのサンプルソース


csv = 'a,b,c,,d,e,,f'
print(csv)
# a,b,c,,d,e,,f

csv_list = list(filter(lambda x: x != "", csv.split(',')))
print(csv_list)
# ['a', 'b', 'c', 'd', 'e', 'f']
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x