【发布时间】:2017-12-21 15:04:42
【问题描述】:
我正在尝试将输入与我创建的名称数组相匹配。这是它的代码:
>>> from fuzzywuzzy import process
>>> names = ["Adam Gilchrist","Adam Barbar","Adam lobiof","Jaffer Wilson","Janet Wilson","Jane Cold"]
>>> process.extract('adamgilchrist',names)
[('Adam Gilchrist', 84), ('Adam lobiof', 50), ('Jane Cold', 50), ('Adam Barbar', 40), ('Janet Wilson', 30)]
我得到的只是名称和信心的数组。
我想将输出显示为 json,如下所示:
{
"results": [
{
"name": "Adam Gilchrist",
"confidence": 84
},
{
"name": "Adam lobiof",
"confidence": 50
},
{
"name": "Jane Cold",
"confidence": 50
},
{
"name": "Adam Barbar",
"confidence": 40
},
{
"name": "Janet Wilson",
"confidence": 30
}
]
}
我在 Windows 10 系统上使用 python 2.7
【问题讨论】:
标签: python arrays json python-2.7 python-3.x