Python filter 去除list中的None 和 空字符串
【摘要】 环境信息ModelArtsNotebook - pytorch1.4-cuda10.1-cudnn7-ubuntu18.04JupyterLab - Notebook - Conda-python3 filter 去除list中的None 和 空字符串my_list= [1,2,3,"abc","",None,4,"QAQ",None,""]my_list[1, 2, 3, 'abc',...
环境信息
- ModelArts
- Notebook - pytorch1.4-cuda10.1-cudnn7-ubuntu18.04
- JupyterLab - Notebook - Conda-python3
- Notebook - pytorch1.4-cuda10.1-cudnn7-ubuntu18.04
filter 去除list中的None 和 空字符串
my_list= [1,2,3,"abc","",None,4,"QAQ",None,""]
my_list
[1, 2, 3, 'abc', '', None, 4, 'QAQ', None, '']
result = filter(lambda x: (x is not None) and (x != ""),my_list)
list(result)
[1, 2, 3, 'abc', 4, 'QAQ']
result
<filter at 0x7f32bfd73a90>
help
help(filter)
Help on class filter in module builtins:
class filter(object)
| filter(function or None, iterable) --> filter object
|
| Return an iterator yielding those items of iterable for which function(item)
| is true. If function is None, return the items that are true.
|
| Methods defined here:
相关链接
备注
- 欢迎各位同学一起来交流学习心得^_^
- 在线课程、沙箱实验、认证、论坛和直播,其中包含了许多优质的内容,推荐了解与学习。
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)