請原諒標題中的含糊不清 - 我不太確定如何解釋我的問題。高效的Python數據存儲(抽象數據類型?)
給定一個字符串:
blah = "There are three cats in the hat"
和(我不知道如何使用這個數據結構) 「用戶信息」:
cats -> ("tim", "1 infinite loop")
three -> ("sally", "123 fake st")
three -> ("tim", "1 infinite loop")
three cats -> ("john", "123 fake st")
four cats -> ("albert", "345 real road")
dogs -> ("tim", "1 infinite loop")
cats hat -> ("janet", NULL)
正確的輸出應該是:
tim (since 'cats' exists)
sally (since 'three' exists)
tim (since 'three' exists)
john (since both 'three' and 'cats' exist)
janet (since both 'cats' and 'hat' exist somewhere in the string blah)
我想要一個有效的方式來存儲這些數據。有可能匹配多個'三'字符串(即,150人將擁有該字符串)。我是否應該有一個包含所有這些數據的列表並複製「密鑰」?
我很困惑,你實際上試圖在這裏做。你能給一個簡潔的英文解釋你的算法和數據結構需要做什麼嗎? – 2009-09-08 20:47:24
我相信字符串會自動實現在Python中,所以不要擔心重複鍵。不是你應該反正。 150 *幾個字節= diddly蹲。 – recursive 2009-09-08 21:00:55
看起來你正在嘗試做某種匹配規則,對吧? 所以,基本上,你有一個輸入字符串「blah」。而且你有一系列匹配規則,對於每個匹配規則,如果左側的每個單詞都包含在字符串中,則右側的名稱(和地址)是輸出的一部分。是對的嗎? – jprete 2009-09-08 21:10:33