【发布时间】:2020-09-28 12:57:09
【问题描述】:
我想创建一个结构如下所示的常量变量:
const example_order_3_lines = [
{
order_id: 111_222_333,
line_items:[
{
title: 'cookie',
quantity: 5,
space: 0.5,
},
{
title: 'md meal',
quantity: 3,
space: 2.0,
},
{
title: 'lg meal',
quantity: 4,
space: 3.0,
},
{
title: 'soup',
quantity: 2,
space: 2.5,
},
{
title: 'apple pie',
quantity: 3,
space: 1,
}
],
},
];
但是当我运行那个单元格时,我得到了这个错误:
File "<ipython-input-60-44a3630eacc1>", line 1
const example_order_3_lines = [
^
SyntaxError: invalid syntax
当我从变量中删除 const 时,会出现此错误:
NameError Traceback (most recent call last)
<ipython-input-64-a12c8a34587f> in <module>
1 example_order_3_lines = [
2 {
----> 3 order_id: 111_222_333,
4 line_items:[
5 {
NameError: name 'order_id' is not defined
谁能帮我看看这有什么问题。
还有我的主要功能:
function __main__() {
const BAG_SIZE = 4;
const results = solve(example_order_3_lines, BAG_SIZE);
console.log('results: ', results[0].bags.length, JSON.stringify(results[0].bags, null, 2));
}
__main__();
主要任务是我想创建一个函数“求解”,它使用“数量”和“空间”来查找包装所需的最小袋子。我想为此使用背包方法。
【问题讨论】:
-
谁告诉你Python有
const? -
还有 111_222_333 很奇怪
-
不错的@dejdej
-
你从哪里得到这个的?这不是有效的 Python 语法。
-
这看起来就像您将一堆其他语言复制粘贴到 Python 程序中并期望它能够运行。 (也许是 Typescript 什么的。)
标签: python list algorithm dictionary