我有像這樣的詞典列表:匹配詞典列表的最有效方法是什麼?
lst = [{'City or Community': 'Augusta', 'State':'GA', 'Parent Company': 'WoW!'},
{'City or Community': 'Augusta', 'State':'GA', 'Parent Company': 'Comcast'}]
什麼是通過列表迭代找到一個地方城市/州有超過1分的結果情況下,最有效的方法是什麼?
這就是我現在所做的:
def search(complete):
#searching through the full list for footprints which overlap by city, county, state, etc
trial = []
for y in complete:
for x in complete:
for subdicts in y:
for otherdicts in x:
if otherdicts['Parent Company'] != subdicts['Parent Company'] and (otherdicts['City or Community'], otherdicts['State']) == (subdicts['City or Community'], subdicts['State']):
不錯的方法,但只假設列表中的字典被正確排序*爲groupby正常工作.. – alecxe
@alexce:好點。 Austin Hasting的解決方案更好。 – Amadan