亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何優化 json 數據對象中 10 個最常用詞的檢索?

如何優化 json 數據對象中 10 個最常用詞的檢索?

忽然笑 2021-09-25 21:53:14
我正在尋找使代碼更高效的方法(運行時和內存復雜性) 我應該使用像 Max-Heap 這樣的東西嗎?由于字符串連接或字典排序不就地或其他原因導致的性能不佳? 編輯:我將字典/地圖對象替換為在所有檢索到的名稱列表上應用 Counter 方法(有重復)最小請求: 腳本應該花費少于 30 秒 當前運行時間:它需要 54 秒   # Try to implement the program efficiently (running the script should take less then 30 seconds)import requests# Requests is an elegant and simple HTTP library for Python, built for human beings.# Requests is the only Non-GMO HTTP library for Python, safe for human consumption.# Requests is not a built in module (does not come with the default python installation), so you will have to install it:# http://docs.python-requests.org/en/v2.9.1/# installing it for pyCharm is not so easy and takes a lot of troubleshooting (problems with pip's main version)# use conda/pip install requests insteadimport json# dict subclass for counting hashable objectsfrom collections import Counter#import heapqimport datetimeurl = 'https://api.namefake.com'# a "global" list object. TODO: try to make it "static" (local to the file)words = []###################################################################################### Calls the site http://www.namefake.com  100 times and retrieves random names# Examples for the format of the names from this site:# Dr. Willis Lang IV# Lily Purdy Jr.# Dameon Bogisich# Ms. Zora Padberg V# Luther Krajcik Sr.# Prof. Helmer Schaden            etc....#####################################################################################
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 174 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號