読者です 読者をやめる 読者になる 読者になる

When it’s ready.

出来るまで出来ない

辞書内包表記

これいいんじゃないか?

% python3.0
Python 3.0 (r30:67503, Feb 28 2009, 18:36:53) 
[GCC 4.0.1 (Apple Inc. build 5490)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a = range(1,11)
>>> b = range(11,21)
>>> a
range(1, 11)
>>> b
range(11, 21)
>>> 
>>> { k:v for k in a for v in b }
{1: 20, 2: 20, 3: 20, 4: 20, 5: 20, 6: 20, 7: 20, 8: 20, 9: 20, 10: 20}
>>> c = { k:v for k in a for v in b }
>>> c
{1: 20, 2: 20, 3: 20, 4: 20, 5: 20, 6: 20, 7: 20, 8: 20, 9: 20, 10: 20}
>>> type(c)
<class 'dict'>
>>>