如何使用索引从以下嵌套字典中提取 'hello'?
How to extract 'hello' from the following nested dictionary using indexing?
How can I extract hello from the code using indexing?
I_say = {'stairs_1':[1, 'two', {'stairs_2':['Close to the door', {'in the door':['one', 2, ['hello']]}]}]}
如果您重新格式化代码并使其更具可读性,将会对您有很大帮助。
{
"stairs_1":[
1,
"two",
{
"stairs_2":[
"Close to the door",
{
"in the door":[
"one",
2,
[
"hello"
]
]
}
]
}
]
}
看完这段代码,你会发现第一层是一个字典,有一个键stairs_1
,它的值是一个包含三个值的列表。
第三个值是一个只包含一个元素的字典。同样,stairs_2
是键,值是一个列表,这次是两个元素。
第二个元素是一个包含一个元素的字典,它的键是in the door
,值是一个列表。
该列表包含三个元素,而第三个是包含单个元素的列表 - 您的 "hello"
字符串。
所以答案是I_say['stairs_1'][2]['stairs_2'][1]['in the door'][2][0]
How can I extract hello from the code using indexing?
I_say = {'stairs_1':[1, 'two', {'stairs_2':['Close to the door', {'in the door':['one', 2, ['hello']]}]}]}
如果您重新格式化代码并使其更具可读性,将会对您有很大帮助。
{
"stairs_1":[
1,
"two",
{
"stairs_2":[
"Close to the door",
{
"in the door":[
"one",
2,
[
"hello"
]
]
}
]
}
]
}
看完这段代码,你会发现第一层是一个字典,有一个键stairs_1
,它的值是一个包含三个值的列表。
第三个值是一个只包含一个元素的字典。同样,stairs_2
是键,值是一个列表,这次是两个元素。
第二个元素是一个包含一个元素的字典,它的键是in the door
,值是一个列表。
该列表包含三个元素,而第三个是包含单个元素的列表 - 您的 "hello"
字符串。
所以答案是I_say['stairs_1'][2]['stairs_2'][1]['in the door'][2][0]