我有两个列表......一个是广告公司,另一个是他们的客户......我希望有一个字典格式的输出,向我展示他们所服务的所有客户的广告公司。
{agency:{company1, company2 etc etc}}
Advertising Agency Company
WPP Alienware
OMNICOM Alleghany Corporation
XYZ Allegheny Technologies
MEDIACOM Allegis Group
XYZ Allen Organ Company
MEDIACOM Allergan
WPP Alliance Rubber Company
OMNICOM Alliant Energy
XYZ Alliant Techsystems
MEDIACOM Allied Insurance
WPP Allison Transmission
OMNICOM Allstate
XYZ Ally Financial
MEDIACOM Aloha Air Cargo
答案 0 :(得分:0)
一种简单的方法是使用collections.defaultdict:
answer = defaultdict(set)
for agency, company in zip(agencies, companies):
answer[agency].add(company)