简体   繁体   English

如何使用python查找大型json文件的值中存在的所有单词

[英]How to find all the word present in a values of large json file using python

I have a huge json file, which contains number of key, value pair我有一个巨大的 json 文件,其中包含键值对的数量

For example:例如:

[

{"header": "hi", "description": " It contain some value ","file_name": "sile.xls", "file_path": "/home", "id": "12"}, 

{"header": "hello", "description": "it has value", "file_name": "s.docs", "file_path": "/home",  "id": "34"}

]

enter image description here在此处输入图片说明

I want output wrt key[description] :我想要输出wrt key[描述]:

---> it -2 , contain-1, some-1, value-2, has-1 ---> it -2 , contains-1, some-1, value-2, has-1

Please help please请帮忙

Input输入

inp = [{'file_path': '/home', 'header': 'hi', 'id': '12', 'description': ' It contain some value ', 'file_name': 'sile.xls'}, {'file_path': '/home', 'header': 'hello', 'id': '34', 'description': 'it has value', 'file_name': 's.docs'}]

Code代码

res={}
for i in inp:
   k = i['description'].split()
   for n in k:
      if not n in res:
            res[n]=1
      else:
            res[n] +=1
print(res)

Output输出

{'some': 1, 'it': 1, 'value': 2, 'It': 1, 'contain': 1, 'has': 1}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM