[perl-python] 20050118 keyed list

X

Xah Lee

© # -*- coding: utf-8 -*-
©
© # in Python, there's a special type of
© # data structure called keyed list. it
© # is a unordered list of pairs, each
© # consists of a key and a value. It is
© # also known as dictionary.
©
© # define a keyed list
© aa = {'john':3, 'mary':4, 'jane':5, 'vicky':7}
© print aa
©
© # getting value from a key
© print 'mary is', aa['mary']
©
© # delete an entry
© del aa['vicky']
© print aa
©
© # get just the keys
© print aa.keys()
©
© # check if a key exists
© print aa.has_key('mary')
©
© # to learn more,
© # type help() and DICTIONARIES
© # or see
© # http://python.org/doc/2.3.4/tut/node7.html
©
© -------------------------------------------
© # in perl, keyed-list is done like this:
©
© %a = ('john',3, 'mary', 4, 'jane', 5, 'vicky',7);
© use Data::Dumper qw(Dumper);
© print Dumper \%a;
©
© # the syntax of keyed list in Perl is too complex
© # to be covered in a short message.
© # see "perldoc perldata" for an unix-styled course.
©
© Xah
© (e-mail address removed)
© http://xahlee.org/PageTwo_dir/more.html
 
J

Jay Tilton

: # the syntax of keyed list in Perl is too complex
: # to be covered in a short message.

You've got to be joking. You couldn't even muster enough skill to provide
Perl equivalents for the four simple Python statements you showed?

: # see "perldoc perldata" for an unix-styled course.

It's good to see your opinion on the _fantastic incompetent writting_[1] of
Perl's documentation has changed enough that you can recommend it to
novices.

[1]Message-ID: <[email protected]>
 
J

Jürgen Exner

Xah said:
© # in perl, keyed-list is done like this:

Just FYI: those thingies are called hashes. The legacy name would be
associative array.
© %a = ('john',3, 'mary', 4, 'jane', 5, 'vicky',7);
© use Data::Dumper qw(Dumper);
© print Dumper \%a;

Wow, my compliments. The very first time that using Data::Dumper actually
may do something useful (formats the data more nicely). Still, why you are
passing a reference is beyond me.
© # the syntax of keyed list in Perl is too complex
© # to be covered in a short message.

Excuse me? If (using the same examples as for your Python section)
print "Mary is $a{mary}";
delete $a{vicky}; print %a;
print keys(%a);
exists $a{mary};
is too complex for your to cover, then I strongly suggest you stop posting
your "explanations".
© # see "perldoc perldata" for an unix-styled course.

Excuse me? Do you mind explaining where exactly perldata is "Unix-styled"?

jue
 
T

Tassilo v. Parseval

Also sprach Jürgen Exner:
Xah Lee wrote:

Wow, my compliments. The very first time that using Data::Dumper actually
may do something useful (formats the data more nicely). Still, why you are
passing a reference is beyond me.

How else would you use 'Dumper' on a hash?

Tassilo
 
J

Jürgen Exner

Tassilo said:
Also sprach Jürgen Exner:


How else would you use 'Dumper' on a hash?

Well, fair enough. If you do a plain
print Dumper(%a);
you do loose a lot of the nifty pretty printing that is provided by Dumper
otherwise.

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top