我有如下字典:
{
"result" : [{
"conf" : 1.000000,
"end" : 105.570000,
"start" : 104.970000,
"word" : "today"
}, {
"conf" : 1.000000,
"end" : 106.320000,
"start" : 106.080000,
"word" : "yes"
}, {
"conf" : 1.000000,
"end" : 106.590000,
"start" : 106.320000,
"word" : "sir"
}],
"text" : "today yes sir"
}
我想从位于结果内的内部字典中提取start
和word
变量。
我该怎么做呢?任何帮助将不胜感激。
答案 0 :(得分:0)
提供您的字典:
my_dict = {
"result" : [{
"conf" : 1.000000,
"end" : 105.570000,
"start" : 104.970000,
"word" : "today"
}, {
"conf" : 1.000000,
"end" : 106.320000,
"start" : 106.080000,
"word" : "yes"
}, {
"conf" : 1.000000,
"end" : 106.590000,
"start" : 106.320000,
"word" : "sir"
}],
"text" : "today yes sir"
}
然后
start = my_dict['result'][0]['start']
word = my_dict['result'][0]['word']
答案 1 :(得分:0)
这是您给的字典:
wget -P /etc/yum.repos.d/ https://nexus.lab.fiware.org/repository/raw/public/repositories/el/7/x86_64/fiware-release.repo
--2020-10-29 11:40:54-- https://nexus.lab.fiware.org/repository/raw/public/repositories/el/7/x86_64/fiware-release.repo
Resolving nexus.lab.fiware.org (nexus.lab.fiware.org)... 109.234.71.209
Connecting to nexus.lab.fiware.org (nexus.lab.fiware.org)|109.234.71.209|:443... connected.
HTTP request sent, awaiting response... 404 public/repositories/el/7/x86_64/fiware-release.repo
2020-10-29 11:40:54 ERROR 404: public/repositories/el/7/x86_64/fiware-release.repo
这可以获取所有的“单词”和“开始”值:
dict ={
"result" : [{
"conf" : 1.000000,
"end" : 105.570000,
"start" : 104.970000,
"word" : "today"
}, {
"conf" : 1.000000,
"end" : 106.320000,
"start" : 106.080000,
"word" : "yes"
}, {
"conf" : 1.000000,
"end" : 106.590000,
"start" : 106.320000,
"word" : "sir"
}],
"text" : "today yes sir"
}