[perl-python] 20050118 keyed list

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Xah Lee

    #1

    [perl-python] 20050118 keyed list

    © # -*- 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('mar y')
    ©
    © # 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
    © xah@xahlee.org
    © http://xahlee.org/PageTwo_dir/more.html

  • Jay Tilton

    #2
    Re: [perl-python] 20050118 keyed list

    "Xah Lee" <xah@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: <7fe97cc4.04012 42131.22acf485@ posting.google. com>

    Comment

    • Jürgen Exner

      #3
      Re: [perl-python] 20050118 keyed list

      Xah Lee wrote:[color=blue]
      > © # in perl, keyed-list is done like this:[/color]

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

      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.
      [color=blue]
      > © # the syntax of keyed list in Perl is too complex
      > © # to be covered in a short message.[/color]

      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 "explanatio ns".
      [color=blue]
      > © # see "perldoc perldata" for an unix-styled course.[/color]

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

      jue


      Comment

      • Tassilo v. Parseval

        #4
        Re: [perl-python] 20050118 keyed list

        Also sprach Jürgen Exner:
        [color=blue]
        > Xah Lee wrote:[/color]
        [color=blue][color=green]
        >> © %a = ('john',3, 'mary', 4, 'jane', 5, 'vicky',7);
        >> © use Data::Dumper qw(Dumper);
        >> © print Dumper \%a;[/color]
        >
        > 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.[/color]

        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{rehtona bus})!JAPH!qq(r ehtona{tsuJbus# ;
        $_=reverse,s+(? <=sub).+q#q!'"q q.\t$&."'!#+sex isexiixesixeseg ;y~\n~~dddd;eva l

        Comment

        • Reinhold Birkenfeld

          #5
          Re: [perl-python] 20050118 keyed list

          Jay Tilton wrote:
          [color=blue]
          >: # the syntax of keyed list in Perl is too complex
          >: # to be covered in a short message.[/color]

          JFTR: "keyed lists" are called dictionaries in Python.
          [color=blue]
          >
          > [1]Message-ID: <7fe97cc4.04012 42131.22acf485@ posting.google. com>
          >[/color]

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

          Reinhold

          Comment

          • Reinhold Birkenfeld

            #6
            Re: [perl-python] 20050118 keyed list

            Jürgen Exner wrote:
            [color=blue][color=green]
            >> © # see "perldoc perldata" for an unix-styled course.[/color]
            >
            > Excuse me? Do you mind explaining where exactly perldata is "Unix-styled"?[/color]

            Remember: Perl == Unix == Satan.

            Reinhold

            Comment

            • Jürgen Exner

              #7
              Re: [perl-python] 20050118 keyed list

              Tassilo v. Parseval wrote:[color=blue]
              > Also sprach Jürgen Exner:
              >[color=green]
              >> Xah Lee wrote:[/color]
              >[color=green][color=darkred]
              >>> © %a = ('john',3, 'mary', 4, 'jane', 5, 'vicky',7);
              >>> © use Data::Dumper qw(Dumper);
              >>> © print Dumper \%a;[/color]
              >>
              >> 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.[/color]
              >
              > How else would you use 'Dumper' on a hash?[/color]

              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


              Comment

              Working...