a clean way to define dictionary

Gerrit Holl gerrit at nl.linux.org
Wed Jun 18 04:49:53 EDT 2003


Matt Gerrans wrote:

> I just had a very similar task today; I would build your dictionary like
> this:
> 
> items = {}
> for pair in [line.split() for line in lst.split('\n')]:

You may want to use .splitlines() rather than .split('\n').

Gerrit.

-- 
32. If a chieftain or a man is captured on the "Way of the King" (in
war), and a merchant buy him free, and bring him back to his place; if he
have the means in his house to buy his freedom, he shall buy himself free:
if he have nothing in his house with which to buy himself free, he shall
be bought free by the temple of his community; if there be nothing in the
temple with which to buy him free, the court shall buy his freedom. His
field, garden, and house shall not be given for the purchase of his
freedom.
        -- 1780 BC, Hammurabi, Code of Law
--
Asperger Syndroom - een persoonlijke benadering:
	http://people.nl.linux.org/~gerrit/
Het zijn tijden om je zelf met politiek te bemoeien:
	http://www.sp.nl/





More information about the Python-list mailing list