On Sat, Feb 5, 2011 at 6:38 PM, Lisa Fritz Barry Griffin <
lisaochba...@gmail.com> wrote:

> Hi there,
>
> How can I do this in a one liner:
>
>        maxCountPerPhraseWordLength = {}
>        for i in range(1,MAX_PHRASES_LENGTH+1):
>            maxCountPerPhraseWordLength[i] = 0
>

maxCountPerPhraseWordLength = {}
[maxCountPerPhraseWordLength.setdefault(i, 0) for i
in range(1,MAX_PHRASES_LENGTH+1)]

>From setdefaults documentation,
'D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D'



>
> Thanks!
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
~l0nwlf
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to