Can I build a dictonary with a list-comprehension?

Marcin 'Qrczak' Kowalczyk qrczak at
Mon Sep 3 16:57:43 CEST 2001

Mon, 3 Sep 2001 12:39:59 +0400 (MSD), Roman Suzi <rnd at> 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
  ^^                      SYGNATURA ZASTĘPCZA

More information about the Python-list mailing list