Skip to main content
added 158 characters in body
Source Link
{k: v for line in txt for k, v in [line.split('=')]}

Advantage over superb rain's answer is ability to modify k and v if needed. Slight memory & speed advantage by avoiding allocation via a generator (credit @GZ0):

{k: v for k, v in (line.split('=') for line in txt)}
{k: v for line in txt for k, v in [line.split('=')]}

Advantage over superb rain's answer is ability to modify k and v if needed.

{k: v for line in txt for k, v in [line.split('=')]}

Advantage over superb rain's answer is ability to modify k and v if needed. Slight memory & speed advantage by avoiding allocation via a generator (credit @GZ0):

{k: v for k, v in (line.split('=') for line in txt)}
deleted 100 characters in body
Source Link
{k: v for line in txt for k, v in [line.split('=')]}

Doubt it gets any shorter or simpler, just requires familiarity with a double for-loop in comprehension. Strong advantageAdvantage over duplicating potentially long operations in outer loopsuperb rain's answer is ability to modify k and v if needed.

{k: v for line in txt for k, v in [line.split('=')]}

Doubt it gets any shorter or simpler, just requires familiarity with a double for-loop in comprehension. Strong advantage over duplicating potentially long operations in outer loop.

{k: v for line in txt for k, v in [line.split('=')]}

Advantage over superb rain's answer is ability to modify k and v if needed.

Post Undeleted by OverLordGoldDragon
Post Deleted by OverLordGoldDragon
Source Link

{k: v for line in txt for k, v in [line.split('=')]}

Doubt it gets any shorter or simpler, just requires familiarity with a double for-loop in comprehension. Strong advantage over duplicating potentially long operations in outer loop.