[Tutor] Dictionary get method

Phil phil_lor at bigpond.com
Wed Mar 20 06:59:25 CET 2013


On 20/03/13 15:09, Mitya Sirenef wrote:
<cut>

>
> By the way, you can further simplify it by doing:
>
> def histogram2(s):
>      return {c: d.get(c,0)+1 for c in s}
>
>
> That will work in python 3, in python 2 you need:
>
>      return dict((c: d.get(c,0)+1) for c in s)
>

Thanks again Mitya, although I'm not sure it's a simplification at my 
present level.

-- 
Regards,
Phil


More information about the Tutor mailing list