On 03/20/2013 04:21 AM, Peter Otten wrote:
Phil wrote:
On 20/03/13 15:09, Mitya Sirenef wrote:
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)
Phil wrote:
> On 20/03/13 15:09, Mitya Sirenef wrote:
>
>
>>
>> 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)
>
On 20/03/13 15:09, Mitya Sirenef wrote:
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 sur
On 20/03/13 14:54, Amit Saha wrote:
Hello Phil,
On Wed, Mar 20, 2013 at 12:54 PM, Phil wrote:
Thank you for reading this.
I'm working my way through a series of exercises where the author only
provides a few solutions.
The reader is asked to modify the histogram example so that it uses the g
On 03/20/2013 01:09 AM, Mitya Sirenef wrote:
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)
Sorry, it should use a comma:
return
On 03/19/2013 10:54 PM, Phil wrote:
Thank you for reading this.
>
> I'm working my way through a series of exercises where the author
only provides a few solutions.
>
> The reader is asked to modify the histogram example so that it uses
the get method thereby eliminating the if and else state
Hello Phil,
On Wed, Mar 20, 2013 at 12:54 PM, Phil wrote:
> Thank you for reading this.
>
> I'm working my way through a series of exercises where the author only
> provides a few solutions.
>
> The reader is asked to modify the histogram example so that it uses the get
> method thereby eliminati
On 03/19/2013 10:54 PM, Phil wrote:
Thank you for reading this.
>
> I'm working my way through a series of exercises where the author
only provides a few solutions.
>
> The reader is asked to modify the histogram example so that it uses
the get method thereby eliminating the if and else state
Thank you for reading this.
I'm working my way through a series of exercises where the author only
provides a few solutions.
The reader is asked to modify the histogram example so that it uses the
get method thereby eliminating the if and else statements. Histogram2 is
my effort.
The resul