首页 > 解决方案 > 通过拆分 python 列表中的每个项目填充的字典键和值

问题描述

我正在尝试将此列表拆分为两个列表,然后将其填充到键和项的字典中。

我有每个行业的声明列表,并希望将此列表分成两个列表。1 与报表和 1 与行业。然后,行业将成为字典的键,语句为值。

['“Significant shortages of personal protective equipment PPE, chemical reagents, test swabs and other basic medical supplies persist. Extreme sourcing measures are required to procure necessary supplies for basic operations. Distributor allocations continue across the board.” Health Care & Social Assistance', '“Severe impact to operations as a result of COVID-19. Major challenges in obtaining needed supplies for first responders, including N95 masks, gowns, disinfecting products and medical supplies. As a local government, we are experiencing a significant increase in activity due to emergency-response efforts. Starting to experience inappropriate price increases for short-supply items.” Public Administration', '“Significant demand disruption caused by the coronavirus.” Accommodation & Food Services', '“The coronavirus is having an impact, but not as much as we thought it would at this point. All sectors are staying busy. Although there are many customer concerns, we are finding work-arounds and adapting to the ever-changing situation.” Construction', '“COVID-19 shelter-in-place order in effect. Offices closed except for essential personnel.” Educational Services', '“Like most businesses, we cannot fully project how the coronavirus will impact us. By displaying prudence and avoiding panic, we are trying to navigate this crisis. As human capital is our greatest expense, protecting that capital is job one. Supply chains are overstressed and will normalize only when the panic subsides.” Information', '“COVID-19 has greatly impacted daily operations. All staff personnel are telecommuting, and customer concerns have shifted from normal activities to preventative measures.” Management of Companies & Support Services', '“We are experiencing no real issues from a business perspective, although COVID-19 has forced us to reconsider elements of how our workforce gets things done.” Mining', '“As expected for many industries whether manufacturing or non-manufacturing, purchasing has slowed as we evaluate the economic climate and prepare for long-term effects.” Retail Trade', '“The coronavirus is effecting every aspect of business.” Real Estate, Rental & Leasing']

理想的结果是这样拆分两个列表:

New List 1 = [“Significant shortages of personal protective equipment PPE, chemical reagents, test swabs and other basic medical supplies persist. Extreme sourcing measures are required to procure necessary supplies for basic operations. Distributor allocations continue across the board.”, ....., “The coronavirus is effecting every aspect of business.”]

New List 2 = [Health Care & Social Assistance, ....., Real Estate, Rental & Leasing]

列表 2 将成为字典的键,列表 1 将成为存储的值。

dictionary = dict(zip(List2,List1))

谢谢您的帮助。

标签: pythonlistsplitdictionary-comprehension

解决方案



推荐阅读