私はそうのような辞書のリストを持っている:ディクショナリのリストと一致させる最も効率的な方法は何ですか?
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