我正在使用pyexcel,当我从字典中得到一个工作表时,它会按字母顺序排序。如何禁用该功能?
我尝试在文档中搜索有关排序的信息,但什么也没有找到。
例如,在这段代码中,我有两行:蔬菜和水果。但在输出中,它改变了按字母顺序排序的顺序。
代码:
import pyexcel as p
vegetables = ['tomato', 'corn', 'onion']
fruits = ['banana', 'apple', 'orange']
food = {
'Vegetables': vegetables,
'Fruits': fruits,
}
sheet = p.get_sheet(adict=food)
print(sheet)输出:
pyexcel_sheet1:
+--------+------------+
| Fruits | Vegetables |
+--------+------------+
| banana | tomato |
+--------+------------+
| apple | corn |
+--------+------------+
| orange | onion |
+--------+------------+预期输出:
pyexcel_sheet1:
+------------+---------+
| Vegetables | Fruits |
+------------+---------+
| tomato | banana |
+------------+---------+
| corn | apple |
+------------+---------+
| onion | orange |
+------------+---------+发布于 2019-08-23 08:25:52
使用OrderedDict() collections.OrderedDict实现的
food = OrderedDict({
'Vegetables': vegetables,
'Fruits': fruits,
})https://stackoverflow.com/questions/57547024
复制相似问题