# reference :https://blog.csdn.net/SL_logR/article/details/82711846
import json
if __name__ == '__main__':
n, m = map(int, input().split())
# convert json str to obj
jstr = ''
for _ in range(n):
jstr += input()
obj = json.loads(jstr)
# get query list
query_list = []
for _ in range(m):
query_list.append(input())
# deal each query
for query in query_list:
q = query.split('.')
# eval_str = 'obj' + ''.join([".get(" + repr(it) + ')' for it in q])
eval_str = 'obj' + ''.join(["[" + repr(it) + "]" for it in q])
# 求表达式的值
# print(eval_str)
try:
res = eval(eval_str)
if type(res) == str:
print("STRING ", res)
elif type(res) == dict:
print("OBJECT")
except Exception: # 可能發生其他錯誤
print("NOTEXIST")
注意最后的异常不能只捕获KeyError,否则只有80分
9万+

被折叠的 条评论
为什么被折叠?



