On Fri, Oct 30, 2009 at 6:46 AM, Shashwat Anand wrote:
> @Navin : Thanks
>
> in case #2:
> "reduce(lcm2, mylist)" works fine
>
Depends upon what you want the behavior to be when mylist is empty. Sending
in a start of '1' will give you '1' as the lcm of an empty list. Sending in
nothing will resu
@Navin : Thanks
in case #2:
"reduce(lcm2, mylist)" works fine
On Fri, Oct 30, 2009 at 5:58 AM, Navin Kabra wrote:
> > Something like this should work:
> > def lcm2(a, b):
> > return a*b/fractions.gcd(a,b)
> >
> > def lcm(mylist):
> > return reduce(lcm2, mylist)
> >
>
> Actually, this probab
> Something like this should work:
> def lcm2(a, b):
> return a*b/fractions.gcd(a,b)
>
> def lcm(mylist):
> return reduce(lcm2, mylist)
>
Actually, this probably should be "reduce(lcm2, mylist, 1)"
navin.
___
BangPypers mailing list
BangPypers@pytho
On Fri, Oct 30, 2009 at 5:31 AM, Shashwat Anand wrote:
> *# 1:*
>
> >>> sum([1, 2, 3], 4)
> 10
>
> How does it actually work ?
> ( ( (1 + 2) + 3) + 4) or ( ( (4 + 1) + 2 + 3)
>
( ( (4 + 1) + 2 + 3)
4 is the 'start'
> >>> sum ( [ [ 1 ], [ 2, 3 ] ], [ ])
> [1, 2, 3]
> What's happening here exact
*# 1:*
>>> sum([1, 2, 3], 4)
10
How does it actually work ?
( ( (1 + 2) + 3) + 4) or ( ( (4 + 1) + 2 + 3)
sum( ) -> sum: (sequence[, start]), so shouldn't 4 be the 'start' that's
second case ?
"Note that sum(range(n), m) is equivalent to reduce(operator.add, range(n),
m)"
>>> sum ( [ [ 1 ], [