8
A
回答
15
7
邮编两个列表成元组,排序,然后把HTML背出元组:
zipped = zip(timestamps, htmls)
zipped.sort()
sorted_htmls = [html for (timestamp, html) in zipped]
2
枚举将为您提供列表中每个项目的(索引,项目)元组列表。您可以使用索引对其进行排序,以从时间戳列表中读取排序关键字。然后剥离html元素:
sorted_elems = [elem for i,elem in sorted(enumerate(html_elements),
key=lambda x:timestamps[x[0]])]
什么可能会更简单?
0
您可以使用第三方的包叫做more_itertools
:
import more_itertools
timestamps = ["08-11-17", "01-13-17", "11-22-17"]
elements = ["<p>", "<b>", "<a href>"]
more_itertools.sort_together([timestamps, elements])
# [('01-13-17', '08-11-17', '11-22-17'), ('<b>', '<p>', '<a href>')]
更多信息请参见more_itertools
docs。
相关问题
- 1. 使用Python排列列表
- 2. 在Python中使用合并排序排序列表
- 3. 排序Python列表
- 4. 排序Python列表
- 5. Python:按“列”排序列表
- 6. Python列表排序的列
- 7. 使用并行排序和多个字段排序列表
- 8. 并行排序两个不同的列表使用jQuery排序
- 9. 并行合并两个排序列表
- 10. 排序列表的列表蟒蛇Python
- 11. 合并排序列表到新列表
- 12. 匹配并插入python排序列表
- 13. 排序和等级列表python并使用python回写到MySQL
- 14. 使用多个键排序Python列表
- 15. 的Python:使用列表合并列表
- 16. Python列表排列
- 17. Python - 对数字列表进行排序
- 18. Python:对列表进行排序
- 19. Python新行是排序列表问题
- 20. Python删除()排序列表?
- 21. Python的 - 排序列表
- 22. 部分排序列表Python
- 23. 排序Python字典列表
- 24. Python排序 - 对象列表
- 25. 如何排序python列表?
- 26. 排序类从Python列表
- 27. 重新排序Python列表
- 28. Python列表,文件排序
- 29. Python:排序依赖列表
- 30. Python:排序列表字典
我怎么不知道'sorted'?谢谢! – Thomas
@Thomas - 别难过! 'sort()'就地,而sorted()'创建一个新列表,所以'sort()'它通常是你想要的大列表。 :-) –
谢谢。向后呢? – Zeno