More random python observations from a perl programmer

aaron_watters at my-deja.com aaron_watters at my-deja.com
Thu Aug 19 20:24:34 CEST 1999


Greetings tchrist.  Hope to shake hands at the ORA conference
soon.

In article <37bc29d8 at cs.colorado.edu>,
  tchrist at mox.perl.com (Tom Christiansen) wrote:
> I keep thinking that everything should work on
> everything.  For example, this surprises me:
>
>     x = {1:2, 3:4}
>     y = {10:20, 30:40}
>     z = x + y
>
> The latter isn't legal.  But in Perl, you can merge hashes easily.
>
>     %x = (1,2,3,4);
>     %y = (10,20,30,40);
>     %z = (%x, %y);

To get exactly what you want you need my kjbuckets extension
( http://www.chordate.com/kjbuckets/index.html ),
but Python has D.update, viz:

>>> x = {1:2, 3:4}
>>> y = {10:20, 30:40}
>>> sum = {}
>>> sum.update(x); sum.update(y)
>>> sum
{30: 40, 3: 4, 10: 20, 1: 2}

But for my purposes this is not too useful since I normally
need to know after a dict union whether the union was ambiguous
(that is, caused key collisions)
or not -- hence the notion of a "dirty" or "clean" kjbuckets
structure.  I suspect the Perl version doesn't flag
ambiguities either, no?

Also, you might find some of the fancier kjbuckets
features (intersect, diff, composition, transitive closure,
reachability, etc) of use as well.
   -- Aaron Watters http://www.chordate.com

===

All generalizations are wrong.



Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




More information about the Python-list mailing list