Python vs. Perl
Thomas Wouters
thomas at xs4all.net
Fri May 25 14:26:33 EDT 2001
On Fri, May 25, 2001 at 10:25:42AM -0700, Jonathan Gardner wrote:
> I'm not trying to rile anyone up, I just want to have someone show me how
> Python excels at dictionaries. Frankly, I find python's syntax a bit
> burdensome and wordy.
You find Python's dict syntax wordy ? Huh ? It's probably the most consise
part of Python (<boast> barring augmented assignment (+=) </boast> :)
Compare:
my %hash = (key => "value", key2 => "value");
(or
my %hash = ("key", "value", "key2", "value");
or
my $hashref = {key => "value", key2 => "value};
if you prefer)
with:
dict = {"key": "value,", "key2": "value"}
Not much wordier ;) Indexing is similarly similar:
$hash{'key'};
vs
dict['key']
as is getting the list of keys or values:
keys %hash;
values %hash;
vs
dict.keys()
dict.values()
Personally, I find the Python syntax much more readable, especially the dict
literals.
You'll-get-used-to-Python-syntax-yet-ly y'rs, ;)
PS: apologies if my perl examples are flawed... I tried to test them, but
testing gets bothersome if the 'interactive interpreter' (perl -de1) isn't
doing what it should ;-P
--
Thomas Wouters <thomas at xs4all.net>
Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
More information about the Python-list
mailing list