Python中的自我重新排序列表 [英] Self reordering list in Python

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

问题描述



您好,


您是否知道如何在
Python中实现真正高效的自我重新排序列表? (具有最大长度的列表。当一个项目被处理时,它将成为列表中的第一个元素。)我想用这个来进行渲染图像的缓存。当然我可以用纯粹的
Python来实现它,我只是想知道是否有一个更快的实现,它使用标准库的一些很酷的功能。 (也许C实现可以将

添加到集合模块中?)


Les


Hello,

Do you know how to implement a really efficient self reordering list in
Python? (List with a maximum length. When an item is processed, it
becomes the first element in the list.) I would like to use this for
caching of rendered images. Of course I could implement this in pure
Python, I just wonder if there is a faster implementation that uses some
cool feature of the standard library. (Maybe a C implementation could be
added to the collections module?)

Les

推荐答案

Am Thu,2005年9月15日15:14:09 +0200 schrieb Laszlo Zsolt Nagy:
Am Thu, 15 Sep 2005 15:14:09 +0200 schrieb Laszlo Zsolt Nagy:

您好,

你知道如何在Python中实现一个非常有效的自我重新排序列表吗? (具有最大长度的列表。当处理项目时,它将成为列表中的第一个元素。)我想使用它来缓存渲染图像。当然我可以在纯Python中实现它,我只是想知道是否有更快的实现使用标准库的一些很酷的功能。 (也许可以将C实现添加到集合模块中?)

Hello,

Do you know how to implement a really efficient self reordering list in
Python? (List with a maximum length. When an item is processed, it
becomes the first element in the list.) I would like to use this for
caching of rendered images. Of course I could implement this in pure
Python, I just wonder if there is a faster implementation that uses some
cool feature of the standard library. (Maybe a C implementation could be
added to the collections module?)







也许是bisect模块是您所需要的:


"此模块支持按排序顺序维护列表

,而无需在每次插入后对列表进行排序。


HTH,

Thomas


-

ThomasGüttler, http://www.thomas-guettler.de/

电子邮件:guettli(*)thomas-guettler + de

垃圾邮件捕手: ni ************** @ thomas-guettler.de



Hi,

Maybe the bisect module is what you need:

"This module provides support for maintaining a list in sorted order
without having to sort the list after each insertion."

HTH,
Thomas

--
Thomas Güttler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
Spam Catcher: ni**************@thomas-guettler.de


2005年9月15日星期四07:14,Laszlo Zsolt Nagy

< ga ***** @ geochemsource.com>

(< ma **** ********************************@python.or g>)写道:
On Thursday 15 September 2005 07:14, Laszlo Zsolt Nagy
<ga*****@geochemsource.com>
(<ma************************************@python.or g>) wrote:
你知道如何实现真正的e在Python中有效的自我重新排序列表?


是。

(具有最大长度的列表。当处理项目时,它将成为列表中的第一个元素。)


搜索移至前列表。如果你想要更大的改进

速度 - O(N * log N)而不是O(N ** 2) - 搜索splay tree;

当然,算法更复杂,优化的算法甚至更复杂。

当然我可以在纯Python中实现它,我只是想知道是否有更快的实现,它使用了标准库的一些很酷的功能。 (也许C实现可以添加到集合
模块中?)
Do you know how to implement a really efficient self reordering list in
Python?
Yes.
(List with a maximum length. When an item is processed, it
becomes the first element in the list.)
Search for "move to front list". If you want a much bigger improvement in
speed -- O(N * log N) instead of O(N**2) -- search for "splay tree"; of
course, the algorithm is more complex and the optimized algorithm is even
more complex.
Of course I could implement this in pure Python, I just wonder if there is
a faster implementation that uses some cool feature of the standard
library. (Maybe a C implementation could be added to the collections
module?)




是的,你可以写一个C语言扩展以提高速度。 />



Yes, you could write a C-language extension for more speed.


Laszlo Zsolt Nagy写道:
Laszlo Zsolt Nagy wrote:
你好,

你知道如何在<中实现真正高效的自我重新排序列表吗? br /> Python? (具有最大长度的列表。当处理项目时,它将成为列表中的第一个元素。)我想使用它来缓存渲染图像。
Hello,

Do you know how to implement a really efficient self reordering list in
Python? (List with a maximum length. When an item is processed, it
becomes the first element in the list.) I would like to use this for
caching of rendered images.




我想知道你为什么不使用字典?我唯一一次使用

移动前端算法存储算法并且必须评估一个

条件来选择正确的算法。这意味着没有恒定的搜索键

可用于访问正确的搜索键。如果我需要做一些模式

识别以便选择正确的图像,如果是图像列表我将实现自我排序列表。持有一个引用

作为搜索关键字,无论使用哪种语言实现,Python的哈希表都会有更好的平均时间复杂度

前移。无论哪种方式,我都会使用Python作为实现语言。

Kay



I wonder why you don''t use a dictionary? The only time I used a
move-front algorithm I stored algorithms and had to evaluate a
condition to select the correct algo. That means no constant search key
was available for accessing the correct one. In case of an image list I
would implement a self-ordering list if I have to do some pattern
recognition in order to select the correct image. Holding a reference
as a search key a Python hash-table will always have a better average
time complexity no matter which language is used to implement
move-front. In either way I''d use Python as an implementation language.
Kay


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

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