我在从字典中制作排序列表时遇到了问题。
我有这个清单
list = [
d = {'file_name':'thisfile.flt', 'item_name':'box', 'item_height':'8.7', 'item_width':'10.5', 'item_depth':'2.2', 'texture_file': 'red.jpg'},
d = {'file_name':'thatfile.flt', 'item_name':'teapot', 'item_height':'6.0', 'item_width':'12.4', 'item_depth':'3.0' 'texture_file': 'blue.jpg'},
etc.
]
我正在尝试遍历列表并
- 从每个字典创建一个包含字典中项目的新列表。 (当用户做出选择时,它会改变哪些项目以及需要附加到列表中的项目数量)
- 对列表进行排序
当我说排序时,我想象创建一个像这样的新字典
order = {
'file_name': 0,
'item_name': 1,
'item_height': 2,
'item_width': 3,
'item_depth': 4,
'texture_file': 5
}
并按顺序字典中的值对每个列表进行排序。
在脚本的一次执行期间,所有列表可能如下所示
['thisfile.flt', 'box', '8.7', '10.5', '2.2']
['thatfile.flt', 'teapot', '6.0', '12.4', '3.0']
另一方面它们可能看起来像这样
['thisfile.flt', 'box', '8.7', '10.5', 'red.jpg']
['thatfile.flt', 'teapot', '6.0', '12.4', 'blue.jpg']
我想我的问题是如何根据字典中的特定值创建列表,并按与第一个字典具有相同键的另一个字典中的值对其进行排序?
感谢任何想法/建议,对菜鸟行为表示歉意 - 我仍在学习 python/编程