是否有任何Python內建或廣泛使用的Python庫在排序序列中執行搜索?搜索排序列表?
Q
搜索排序列表?
16
A
回答
22
13
值得注意的是,有一些高質量的Python庫可用於維護排序列表,這些列表還可實現快速搜索:sortedcontainers和blist。當然,使用這些取決於您插入/移除列表中的元素並需要搜索的頻率。每個模塊都提供一個SortedList類,可以按排序順序高效地維護這些項目。
從排序列表的文檔:
L.bisect_left(value)
Similar to the bisect module in the standard library, this returns
an appropriate index to insert value in L. If value is already present
in L, the insertion point will be before (to the left of) any existing
entries.
L.bisect(value)
Same as bisect_left.
L.bisect_right(value)
Same as bisect_left, but if value is already present in L, the
insertion point will be after (to the right of) any existing entries.
兩種實現使用二進制搜索來查找給定值的正確索引。有一個performance comparison頁面可供選擇這兩個模塊。
免責聲明:我是sortedcontainers模塊的作者。
相關問題
- 1. 對象的搜索和排序列表
- 2. 排序列表,搜索結果等
- 3. 元搜索排序排序列
- 4. Python - 列表的排序列表中的二進制搜索
- 5. 二進制搜索升序排列C++
- 6. 搜索查看結果和排序列
- 7. 搜索與依賴的順序排列
- 8. 當我在搜索的字段上排序時,可以更快地搜索排序的列表<T>嗎?
- 9. 引導+ AngularJS - 如何排序/搜索/編輯/分頁表列
- 10. 需要幫助在表中通過列搜索進行排序
- 11. 二進制搜索已排序的列表<int>
- 12. 遞歸搜索新項目在排序列表中的位置?
- 13. 使用搜索字符串對列表進行排序
- 14. 快速搜索C++中的字符串排序列表
- 15. 排序整數列表中的近似搜索算法
- 16. 的Python:搜索元組的排序列表
- 17. 線性排序搜索
- 18. 排序Lucene搜索結果
- 19. 排序彈性搜索
- 20. 排序/搜索StackedInline選項
- 21. 快速搜索和排序
- 22. 搜索未排序數組
- 23. 在排序時搜索DataGrid
- 24. Mysql全文搜索排序
- 25. Hibernate搜索結果排序
- 26. 搜索,按AJAX排序
- 27. 二進制搜索按列排序的二維數組只搜索第一列
- 28. 彈性搜索排序和排名
- 29. 搜索Python列表
- 30. Python列表搜索
序列是什麼?另外,什麼樣的搜索(二進制等)? – 2010-07-07 16:07:02
我相信問題是試圖成爲「規範」或「通用」,因此「序列」的含義可能是使用[序列的Python文檔定義(即Python 2.x)。有七種序列類型:字符串,Unicode字符串,列表,元組,字節數組,緩衝區和xrange對象。「)](https://docs.python.org/2/library/stdtypes.html#sequence-types-str-unicode-list-tuple -bytearray-buffer-xrange) – 2017-10-25 12:42:51