Can I build a dictonary with a list-comprehension?

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Mon Sep 3 10:57:43 EDT 2001


Mon, 3 Sep 2001 12:39:59 +0400 (MSD), Roman Suzi <rnd at onego.ru> pisze:

> {k: v for k,v in dict if type(v) == type("")} 

Although this:
    dictionary ([(k,v) for k,v in dict.items() if type(v) == str])
is not as concise, it doesn't require new syntax, just standard
library support.

In Python-2.2a1 there is already a buildin variable 'dictionary'
bound to the dictionary type which also acts as a function. But
it currently just ignores its parameters. I don't know the status
of the discussion about how its parameters should look like.

-- 
 __("<  Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTĘPCZA
QRCZAK



More information about the Python-list mailing list