By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,235 Members | 1,057 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,235 IT Pros & Developers. It's quick & easy.

[perl-python] 20050118 keyed list

P: n/a
© # -*- 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
© xa*@xahlee.org
© http://xahlee.org/PageTwo_dir/more.html

Jul 18 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"Xah Lee" <xa*@xahlee.org> wrote:

: # 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: <7f**************************@posting.google.com >

Jul 18 '05 #2

P: n/a
Xah Lee wrote:
© # 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
Jul 18 '05 #3

P: n/a
Also sprach Jürgen Exner:
Xah Lee wrote:

© %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.


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

Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus}) !JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexi ixesixeseg;y~\n~~dddd;eval
Jul 18 '05 #4

P: n/a
Jay Tilton wrote:
: # the syntax of keyed list in Perl is too complex
: # to be covered in a short message.
JFTR: "keyed lists" are called dictionaries in Python.

[1]Message-ID: <7f**************************@posting.google.com >


This guy's wish-wash is starting to be funny, after all!

Reinhold
Jul 18 '05 #5

P: n/a
Jürgen Exner wrote:
© # see "perldoc perldata" for an unix-styled course.


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


Remember: Perl == Unix == Satan.

Reinhold
Jul 18 '05 #6

P: n/a
Tassilo v. Parseval wrote:
Also sprach Jürgen Exner:
Xah Lee wrote:

© %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.


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
Jul 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.