Python vs. Perl

Paul Prescod paulp at
Fri May 25 14:09:27 EDT 2001

Jonathan Gardner wrote:
> I must be missing the point. Please explain how Python is better 
> than Perl in this respect.

I could be wrong but I've seen some pretty weird Perl code for working
with nested data structures. Maybe you can help me by translating this
code which sets up a dictionary with keys as tuples of integers (not
strings) and values as dictionaries of integers to lists.

>>> dict = { (1,2) : {5:[3,4]}, (2,3) : {6:[4,3]}}
>>> print dict[(2,3)][6]
[4, 3]

> "Dictionaries of tuples"
> Perl has as straightforward and easy syntax for making arrays or hashes,
> hashes of arrays, and arrays of arrays or hashes of hashes. The references
> idea may be a bit confusing AT FIRST, but in the end, it is extremely
> powerful and useful - just like C pointers are confusing but end up being
> extremely useful for many things.

Python has all of the power of references without the syntactic
complexity. I've been programming in Python for five years and never
missed pointers once.

> I'm not trying to rile anyone up, I just want to have someone show me how
> Python excels at dictionaries. 

I think I just did. You agreed with me that Perl couldn't easily use
just any object as a key, allow any object to describe how it hashes
itself or easily allow any object to act syntactically as a dictionary.

I'm not going to claim based on that that Python is better than Perl but
I think it is pretty clear that Python dictionaries are more flexible
and easy to use than Perl hashes.
Take a recipe. Leave a recipe.  
Python Cookbook!

More information about the Python-list mailing list