列表清单 [英] list of lists

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

问题描述




我有一个由列表组成的列表。

例如T = [[1,2,3],[4,5],[6]]

有没有办法解决内部中的特定组件?列表

直接?

例如现在我想获得第一个列表的第二个值。

不幸的是我必须首先将它保存到变量然后读取它。

a = T [0]

打印一份[1]


那种糟透了,因为我必须从很多内容中读取很多价值

列出! :-(

有没有比我将它保存到帮助变量更快的方式?


谢谢大家!!


问候,汤姆

解决方案

在文章< bk ********** @ news.uni-kl.de>,Tom写道:



我有一个由列表组成的列表。
例如T = [[1 ,2,3],[4,5],[6]]
有没有办法直接解决内部列表中的特定组件?
例如,现在我想获得第一个列表的第二个值。
不幸的是我必须先将它保存到变量然后再读它。
a = T [0]
打印一个[1]

这种糟糕,因为我必须从很多
列表中读取很多值!:-(
有没有比我保存它更快的方法帮助变量首先?




使用你的例子:


T = [[1,2,3] ,[4,5],[6]]

打印T [0] [1]


Zach


2003年9月15日星期一15:59:56 +0200,Tom写道:


我有一个由列表组成的列表。例如。 T = [[1,2,3],[4,5],[6]]
有没有办法解决内部的特定组成部分。列表
直接?
例如现在我想获得第一个列表的第二个值。
不幸的是我必须先将它保存到变量然后再读取它。 a =
T [0]
打印[1]




尝试使用T [0] [1]。 T [0]完全等同于''a'',所以你可以使用

相同的操作,你不必首先分配给''a'。


Johannes


Tom写道:



我有一个由列表组成的列表。
例如T = [[1,2,3],[4,5],[6]]
有没有办法解决内部的特定组成部分。列表
直接?
例如现在我想获得第一个列表的第二个值。
不幸的是我必须先将它保存到变量然后再读它。
a = T [0]
打印一个[ 1]

那种糟透了,因为我必须阅读很多
列表中的很多值! :-(
有没有比我将它保存到帮助变量更快的方式?

感谢大家!!

此致,汤姆




你的例子而不是你的问题规范表明你想要

所有。如果我猜对了:


def flatten(lol):
$ l $ l for lst in lol:

for item in lst:

yield item


T = [[1,2,3],[4,5],[6]]


for flatten(T) :

打印项目


指数似乎是一个垂死的品种:-)


彼得


Hi,

I have a list that consists of lists.
E.g. T=[[1, 2, 3], [4, 5], [6]]
Is there a way to address the a specific component in the "inner" list
directly?
E.g. right now I want to get the second value of the first list.
Unfortunately I have to save it to a variable first and then read it.
a = T[0]
print a[1]

That kind of sucks, becaus I have to read a lot of values from a lot of
lists! :-(
Is there a faster way than my saving it to a "help variable" first?

Thanks folks!!

Regards, Tom

解决方案

In article <bk**********@news.uni-kl.de>, Tom wrote:

Hi,

I have a list that consists of lists.
E.g. T=[[1, 2, 3], [4, 5], [6]]
Is there a way to address the a specific component in the "inner" list
directly?
E.g. right now I want to get the second value of the first list.
Unfortunately I have to save it to a variable first and then read it.
a = T[0]
print a[1]

That kind of sucks, becaus I have to read a lot of values from a lot of
lists! :-(
Is there a faster way than my saving it to a "help variable" first?



To use your example:

T=[[1, 2, 3], [4, 5], [6]]
print T[0][1]

Zach


On Mon, 15 Sep 2003 15:59:56 +0200, Tom wrote:

Hi,

I have a list that consists of lists. E.g. T=[[1, 2, 3], [4, 5], [6]]
Is there a way to address the a specific component in the "inner" list
directly?
E.g. right now I want to get the second value of the first list.
Unfortunately I have to save it to a variable first and then read it. a =
T[0]
print a[1]



Try using T[0][1]. T[0] is exactly equivalent to ''a'', so you can use
the same operations, you don''t have to assign to ''a'' first.

Johannes


Tom wrote:

Hi,

I have a list that consists of lists.
E.g. T=[[1, 2, 3], [4, 5], [6]]
Is there a way to address the a specific component in the "inner" list
directly?
E.g. right now I want to get the second value of the first list.
Unfortunately I have to save it to a variable first and then read it.
a = T[0]
print a[1]

That kind of sucks, becaus I have to read a lot of values from a lot of
lists! :-(
Is there a faster way than my saving it to a "help variable" first?

Thanks folks!!

Regards, Tom



Your example rather than your problem specification suggests that you want
them all. If I''m guessing right:

def flatten(lol):
for lst in lol:
for item in lst:
yield item

T=[[1, 2, 3], [4, 5], [6]]

for item in flatten(T):
print item

Indices seem to be a dying breed :-)

Peter


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

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