我有一個json文件data_large大小爲150.1MB。該文件中的內容是[{"score": 68},{"score": 78}]
。我需要從每個項目中找到獨特分數的列表。蟒蛇 - 從大的json文件中找到唯一的值很有效
這是我在做什麼: -
import ijson # since json file is large, hence making use of ijson
f = open ('data_large')
content = ijson.items(f, 'item') # json loads quickly here as compared to when json.load(f) is used.
print set(i['score'] for i in content) #this line is actually taking a long time to get processed.
我可以print set(i['score'] for i in content)
線更有效。目前需要執行201secs。它可以變得更有效率嗎?
參見:[上CodeReview.SE這個問題( http://codereview.stackexchange.com/questions/38574/how-to-find-the-unique-values-from-the-json-file)。 – poke