方括号中的ForLoop用于从列表中删除空格。 [英] A ForLoop in square brackets to remove blanks from list.

查看:107
本文介绍了方括号中的ForLoop用于从列表中删除空格。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我在我的代码中运行了这一行并知道它用于从预先建立的中删除空白值:


I have run across this line in my code and know that is used to remove blank values from a pre-established:

disList



我能够根据自己的代码确定其预期结果。



但是,这是一个非常酷的小代码因为需要做什么以及它做得多快。



这种列表操作的常用名称是什么?我很想了解更多关于什么类型的forLoops可以通过方括号传递的限制。还有其他forLoops可以做到这一点(元组,字典?)


I was able to determine its intended result from the context of my own code.

However, it is a very cool little code for what was needed to be done and how fast it did it.

What is the "common name" of this type of list manipulation? I would love to learn more about the limits of what kinds of forLoops can be passed through square brackets. And where else forLoops can do this (tuples, dictionaries?)

推荐答案

它被称为列表理解。

http://www.diveintopython.net/native_data_types/mapping_lists.html [ ^ ]



祝你好运!
It is called list comprehension.
http://www.diveintopython.net/native_data_types/mapping_lists.html[^]

Good luck!


这篇关于方括号中的ForLoop用于从列表中删除空格。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆