排序列表 [英] Sorting a list

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

问题描述

大家好。如果我有一个元组列表,并且每个元组的形式如下:


(年份,文本),如('''''',''这是引用。' ')


我如何对列表进行排序,使其按年份顺序排列?

年份?有没有比制作元组列表更好的方法呢?


(到目前为止,我有一个文本文件,每行都有一个引文。我使用RE

搜索年份,然后将今年和整个引文放在

元组中,并将此元组添加到列表中。也许这一步可以更改为
当我需要按日期对它们进行排序并按顺序写下一个新的

文件时,
会更有效率。)


谢谢。

Hi everyone. If I have a list of tuples, and each tuple is in the form:

(year, text) as in (''1995'', ''This is a citation.'')

How can I sort the list so that they are in chronological order based on
the year? Is there a better way to do this than making a list of tuples?

(So far I have a text file and on each line is a citation. I use an RE
to search for the year, then put this year and the entire citation in a
tuple, and add this tuple to a list. Perhaps this step can be changed to
be more efficient when I then need to sort them by date and write a new
file with the citations in order.)

Thanks.

推荐答案

John Salerno写道:
John Salerno wrote:

大家好。如果我有一个元组列表,并且每个元组的形式如下:


(年份,文本),如('''''',''这是引用。' ')


我如何对列表进行排序,使它们按时间顺序排列
Hi everyone. If I have a list of tuples, and each tuple is in the form:

(year, text) as in (''1995'', ''This is a citation.'')

How can I sort the list so that they are in chronological order



L.sort()


> kad ima1 7 godina glup si ko kurac,sve je predobro:auti?ii bageri u

kvartu。 。到je?ivot"

Drito Konj

L.sort()

--
"kad ima1 7 godina glup si ko kurac, sve je predobro: auti?i i bageri u
kvartu.. to je ?ivot"
Drito Konj


John Salernoaécrit:
John Salerno a écrit :

大家好。如果我有一个元组列表,并且每个元组的形式如下:


(年份,文本),如('''''',''这是引用。' ')


我如何对列表进行排序,使其按年份顺序排列?

年份?
Hi everyone. If I have a list of tuples, and each tuple is in the form:

(year, text) as in (''1995'', ''This is a citation.'')

How can I sort the list so that they are in chronological order based on
the year?



在列表上调用sort()应该可行。

Calling sort() on the list should just work.


有更好的方法吗这比制作一个元组列表?
Is there a better way to do this than making a list of tuples?



取决于......

Depends...


(到目前为止,我有一个文本文件,每行都是一个引用。我使用RE

搜索年份,然后将今年和整个引文放在

元组中,并将此元组添加到列表中。
(So far I have a text file and on each line is a citation. I use an RE
to search for the year, then put this year and the entire citation in a
tuple, and add this tuple to a list.



你不知道这些行是如何格式化的,但你有可能

甚至不需要正则表达式这里。但是wrt / sorting,元组列表

排序键作为第一个元素是最好的解决方案之一。

You don''t tell how these lines are formatted, but it''s possible that you
don''t even need a regexp here. But wrt/ sorting, the list of tuples with
the sort key as first element is one of the best solutions.


Bruno Desthuilliers写道:
Bruno Desthuilliers wrote:

你不知道这些行是如何格式化的,但是你可能不会这样做b
不要甚至需要一个正则表达式。但是wrt /排序,元组列表

排序键作为第一个元素是最好的解决方案之一。
You don''t tell how these lines are formatted, but it''s possible that you
don''t even need a regexp here. But wrt/ sorting, the list of tuples with
the sort key as first element is one of the best solutions.



啊,所以简单地使用sort()将默认为第一个每个元组的元素?


引用如下:


姓氏,名字。 (年)。标题。其他的东西。

Ah, so simply using sort() will default to the first element of each tuple?

The citations are like this:

lastname, firstname. (year). title. other stuff.


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

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