Can python create a dictionary from a list comprehension?

Wim Vogelaar wim.vogelaaratmc2worlddotorg
Mon May 28 04:20:16 EDT 2007


> Example:
>
> a = [1,2,3,4,5,6,7,8,9,10]
>
> aDict = dict([(x,x+1) for x in a if x%2==0])
>
> print aDict
>

When I run this program I get:
{8: 9, 2: 3, 4: 5, 10: 11, 6: 7}

why this output isn't ordered, giving:
{2: 3, 4: 5, 6: 7, 8: 9, 10: 11 }






More information about the Python-list mailing list