Lisp mentality vs. Python mentality

marek.rocki at wp.pl marek.rocki at wp.pl
Sat Apr 25 04:48:29 EDT 2009


Ciprian Dorin, Craciun napisał(a):
> Python way:
> def compare (a, b, comp = eq) :
>  if len (a) != len (b) :
>   return False
>  for i in xrange (len (a)) :
>   if not comp (a[i], b[i]) :
>    return False
>  return True
This is shorter, but I'm not sure if more pythonic:
def compare(a, b, compfunc=eq):
     return all(compfunc(aelem, belem) for aelem, belem in zip_longest
(a, b, fillvalue=object()))

Regards,
Marek



More information about the Python-list mailing list