小码问答,有问必答!

如何删除Python列表list中的空值?

Python

收藏

1个回答

我要回答

  • author
    牛叔叔 2021-11-12 15:14
    data = ['','wanmait','','万码学堂']
    while '' in data:
        data.remove('')



    或者

    data = [i for i in data if i != '']


    或者

    data = list(filter(lambda s:s and s.strip(),data))