[英]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.