看板 Python 關於我們 聯絡資訊
※ 引述《busystudent (busystudent)》之銘言: : 各位好,最近用for迴圈寫了一隻有自動挖掘資料的程式碼,可是最後輸出要呼叫另一隻程式碼時一直失敗。 : 圖文好讀版 http://goo.gl/0DWEnn : 舉例 : 以下為a程式的輸出 : 1. http://www.diigo.com/user/tony_swann/dict : 2. http://goo.gl/gpOs2j : 3. http://goo.gl/Shsur8 : 4. http://www.diigo.com/user/tony_swann/2 : 5. https://goo.gl/SzU7ig 想要這種長相? myDict = {'http://www.diigo.com/user/tony_swann/dict' :['http://goo.gl/gpOs2j','http://goo.gl/Shsur8'] ,'http://www.diigo.com/user/tony_swann/2':['https://goo.gl/SzU7ig'] } print(myDict.keys()) print(myDict['http://www.diigo.com/user/tony_swann/dict']) ====================================?? --Code-- for i in myDict.keys(): print("===" + i + "===") count = 0 for j in myDict[i]: print(j) count += 1 print(count) print("\n") --OutPut-- ===http://www.diigo.com/user/tony_swann/dict=== http://goo.gl/gpOs2j http://goo.gl/Shsur8 2 ===http://www.diigo.com/user/tony_swann/2=== https://goo.gl/SzU7ig 1 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 106.1.129.194 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1461292777.A.F4F.html
octantis: 你這樣哪有解決他的問題...你去RUN一下他的原始碼 04/22 11:34
octantis: 另外存成dict還要考慮key是否唯一 04/22 11:39
busystudent: 你好 謝謝你的回文,我把文章敘述再修改一遍了 04/22 12:07
checkIO: 有分組的話一定要唯一吧 04/22 17:14
checkIO: 他看起來是要大標籤下的所有小標籤運算 所以我想不會有ke 04/22 17:16
checkIO: y重覆這件事 04/22 17:16
busystudent: 謝謝大家回文,關於key重複這件事,其實我大標籤下 04/22 17:23
busystudent: 的小標籤在抓出來後,會有處理重複標籤的步驟,可是 04/22 17:23
busystudent: 有點偏題我的問題,就略過不說了 04/22 17:23
checkIO: 所以大標籤會有重覆的狀況嗎 04/22 17:25
busystudent: 大標籤不會,只有小標籤 04/22 17:29
checkIO: 標籤雲可能會有相關性問題 建議不要去清洗小標籤到唯一 04/22 17:34
checkIO: 那可能是重要相關性 這樣看起來這篇格式可以處理掉你的問 04/22 17:34
checkIO: 題 04/22 17:34
busystudent: 感謝c網友提醒,馬上檢查 04/22 17:54
penguin7272: count 可以直接印 len(myDict[i]) 04/22 20:39