本文介绍了循环列表。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这种类型的结构来自哪里:


mat = ['a''为我的范围(3)]?


这将生成一个包含三个元素的列表但是

我在任何一本书中都没有看到它的参考。

解决方案




它被称为列表理解。因为我不知道你的意思是什么书,所以我不能说它是否覆盖在那里。


-

Diez B. Roggisch




它被称为列表理解它出现在Python 2.0中。




Jeremy Jones





它被称为列表理解,并在Python 2.0中添加。






Python 2.4引入了一种称为生成器表达式的变体:


http://www.python.org/peps/pep-0289.html



< / F>


Where did this type of structure come from:

mat = [''a'' for i in range(3)] ?

This will produce a list of three elements but
I don''t see reference for it in any of the books.

解决方案



Its called a list-comprehension. And as I don''t know what books you mean, I
can''t say if its covered there or not.

--
Regards,

Diez B. Roggisch



It''s called a list comprehension and it appeared in Python 2.0.

http://www.amk.ca/python/2.0/index.h...00000000000000

Jeremy Jones




it''s called "list comprehension", and was added in Python 2.0.

http://www.amk.ca/python/2.0/index.h...00000000000000
http://docs.python.org/tut/node7.htm...00000000000000
http://docs.python.org/ref/lists.html

Python 2.4 introduces a variation called "generator expressions":

http://www.python.org/doc/2.4/whatsnew/node4.html
http://www.python.org/peps/pep-0289.html
http://docs.python.org/ref/genexpr.html

</F>


这篇关于循环列表。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 03:33