![](/img/trans.png)
[英]How can I sort this list according to the crescent order of the element[0] of the tuples?
[英]I have a list of tuples, how can I take out a specific element?
我有一个类似的元组列表:
>>>list
[('the', 248),
('I', 81),
...
('I', 81)]
我想取出一个特定元素,例如('to',248),我应该如何索引该元素并获取它?
>>> l =[('the', 248), ('I', 81), ('I', 81)]
>>> x = [i[1] for i in l]
>>> x
[248, 81, 81]
我不确定这个问题到底是什么意思,但是如果您想删除具有特定质量的元素,则只需使用index()(无论数据类型如何):
# x = [("string0",0),("string1",1),("string2",2),("string3",3)]
# Example outputs:
>>> x.index(("string0",0))
0
>>> x.index(("string2",2))
2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.