Python如何获取二维列表中的每个第一个元素 [英] Python How to get every first element in 2 Dimensional List
本文介绍了Python如何获取二维列表中的每个第一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的列表:
a = ((4.0, 4, 4.0), (3.0, 3, 3.6), (3.5, 6, 4.8))
我想要这样的结果(每个列表中的第一个元素):
I want an outcome like this (EVERY first element in the list) :
4.0, 3.0, 3.5
我尝试了[[:: 1] [0],但不起作用
I tried a[::1][0], but it doesn't work
我几周前才开始学习Python. Python版本= 2.7.9
I'm just start learning Python weeks ago. Python version = 2.7.9
推荐答案
您可以从列表理解的每个元素中获取索引[0]
You can get the index [0]
from each element in a list comprehension
>>> [i[0] for i in a]
[4.0, 3.0, 3.5]
也只是想学什么,您没有list
的list
,却没有tuple
的tuple
.
Also just to be pedantic, you don't have a list
of list
, you have a tuple
of tuple
.
这篇关于Python如何获取二维列表中的每个第一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文