假设我有以下三个列表:
list_1 = [1, 2, 3, 4, 5]
list_2 = ['a', 'b', 'c', 'd', 'e']
list_3 = [1.1, 2.2, 3.3, 4.4]
Run Code Online (Sandbox Code Playgroud)
如何将这三个列表组合成这样:
[
{'int': 1, 'str': 'a', 'float': 1.1},
{'int': 2, 'str': 'b', 'float': 2.2},
{'int': 3, 'str': 'c', 'float': 3.3},
{'int': 4, 'str': 'd', 'float': 4.4},
{'int': 5, 'str': 'e', 'float': 5.5}
]
Run Code Online (Sandbox Code Playgroud)
实现此目的的语法最干净的方法是什么?
谢谢你的帮助!!
假设我有一个下面的数组:
[
{ type: 'senior', schoolName: 'school-A', country: 'America' },
{ type: 'senior', schoolName: 'school-B', country: 'England' },
{ type: 'junior', schoolName: 'school-C', country: 'German' },
{ type: 'junior', schoolName: 'school-D', country: 'Italy' },
]
Run Code Online (Sandbox Code Playgroud)
如何将上面的数组转换为对象,如下所示:
{
senior: {
America: 'school-A',
England: 'school-B'
},
junior: {
German: 'school-C',
Italy: 'school-D'
}
}
Run Code Online (Sandbox Code Playgroud)
完成此任务的语法上最简洁的方法是什么?
谢谢你的帮助!!
我尝试在 Docker 中运行 bash 脚本,但不断收到此错误:
./scripts/proto-generator.sh:第 13 行:语法错误:意外的“(”(期望“then”)
这是我的 proto-generator.sh 文件:
function printGreen() {
printf "\e[0;32m$1\e[0;m\n"
}
function printRed() {
printf "\e[0;31m$1\e[0;m\n"
}
service=$1
outDir=./src/services/$service/models
protoDir=./protos/"${service}Service"/*.proto
if ! [[ "$service" =~ ^(file|user)$ ]]; then
printRed "Incorrect service: $service"
exit 1
fi
./node_modules/.bin/proto-loader-gen-types \
--longs=String \
--enums=String \
--defaults \
--oneofs \
--grpcLib=@grpc/grpc-js \
--outDir=$outDir \
$protoDir
printGreen "GRPC codes generated: ${outDir}"
Run Code Online (Sandbox Code Playgroud)
如何修复语法错误?
谢谢你的帮助!!
arrays ×1
bash ×1
dictionary ×1
docker ×1
dockerfile ×1
javascript ×1
list ×1
node.js ×1
object ×1
python ×1
python-3.x ×1