C#3.0 and lambdas
Scott David Daniels
Scott.Daniels at Acm.Org
Wed Sep 21 12:02:18 EDT 2005
Roel Schroeven wrote:
> ...
> Christophe schreef:
>> ...
>>And what about a function which computes the line length ?
>
> That would have been a better example indeed, since the *p1 trick
> doesn't work there.
>
> def euclidian_distance((x1, y1), (x2, y2)):
> return math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
>
> That's a lot nicer, I think, than this:
>
> def euclidian_distance(p1, p2):
> return math.sqrt((p2[0] - p1[0])**2 + (p2[1] - p1[1])**2)
But not massively nicer than:
def euclidian_distance(p1, p2):
(x1, y1), (x2, y2) = p1, p2
return math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
--Scott David Daniels
Scott.Daniels at Acm.Org
More information about the Python-list
mailing list