[英]How to sort a list of tuples according to the order of a tuple element in another list?
[英]How can I sort this list according to the crescent order of the element[0] of the tuples?
我想要這樣的東西
[( 0 ,'dunno'),( 1 ,'dunno'),( 2 ,'dunno'),( 3 ,'dunno'),( 4 ,'dunno'),( 5 ,'n'),( 6 ,'dunno'),...]
我已經嘗試過
sorted(list_of_tuples, key=lambda x: x[0])
sorted()
不對列表進行排序,它返回一個排序的列表。 如果要就地排序,請改用sort()
方法。
解決方案的一部分在這里。 問題在於,現在開始時,我想在列表的末尾添加一個字符串。
for line in list_of_tuples:
line=line.sort(reverse=False)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.