Dictionary & data

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

    Dictionary & data

    I have retrieved data from a database and I want to place this data into a
    dictionary or something like a HashMap (in Java). Can someone point me to
    an example?

    kbass


  • Simon Burton

    #2
    Re: Dictionary & data

    On Tue, 16 Mar 2004 21:35:14 +0000, kbass wrote:
    [color=blue]
    > I have retrieved data from a database and I want to place this data into a
    > dictionary or something like a HashMap (in Java). Can someone point me to
    > an example?
    >
    > kbass[/color]




    RTFM

    Simon.

    Comment

    • Garry Knight

      #3
      Re: Dictionary & data

      In message <mqK5c.22047$8G 2.9439@fe3.colu mbus.rr.com>, kbass wrote:
      [color=blue]
      > I have retrieved data from a database and I want to place this data into a
      > dictionary or something like a HashMap (in Java). Can someone point me to
      > an example?[/color]

      Here's most of what you'll need to handle dictionaries:

      d1 = {} # create empty dictionary
      d2 = {"one": 1, "two": "two", 3: "three"} # create and populate dictionary
      d3 = {1: 'spam', {'a': 'b'}} # nesting
      d2["two"] = 42 # adding, changing
      d3[1]['a'] = 'c' # changing value in nested dictionary
      x = d2['two'] # fetch using index
      y = d3[1]['a'] # fetch from nested dictionaries
      cnt = len(d2) # get no. of key/value pairs
      del d2[3] # remove key/value
      for k in d2.keys(): # loop over keys
      for v in d2.values(): # loop over values
      for k,v in d2.items(): # loop over key/value pairs
      d = d2.keys; d.sort() # get sorted list of keys

      It's probably a good idea to work your way through the tutorial here:
      The official home of the Python Programming Language


      --
      Garry Knight
      garryknight@gmx .net ICQ 126351135
      Linux registered user 182025

      Comment

      • kbass

        #4
        Re: Dictionary &amp; data


        "Garry Knight" <garryknight@gm x.net> wrote in message
        news:1079475979 .24696.0@lotis. uk.clara.net...
        | In message <mqK5c.22047$8G 2.9439@fe3.colu mbus.rr.com>, kbass wrote:
        |
        | > I have retrieved data from a database and I want to place this data into
        a
        | > dictionary or something like a HashMap (in Java). Can someone point me
        to
        | > an example?
        |
        | Here's most of what you'll need to handle dictionaries:
        |
        | d1 = {} # create empty dictionary
        | d2 = {"one": 1, "two": "two", 3: "three"} # create and populate dictionary
        | d3 = {1: 'spam', {'a': 'b'}} # nesting
        | d2["two"] = 42 # adding, changing
        | d3[1]['a'] = 'c' # changing value in nested dictionary
        | x = d2['two'] # fetch using index
        | y = d3[1]['a'] # fetch from nested dictionaries
        | cnt = len(d2) # get no. of key/value pairs
        | del d2[3] # remove key/value
        | for k in d2.keys(): # loop over keys
        | for v in d2.values(): # loop over values
        | for k,v in d2.items(): # loop over key/value pairs
        | d = d2.keys; d.sort() # get sorted list of keys
        |
        | It's probably a good idea to work your way through the tutorial here:
        | http://www.python.org/doc/2.3.3/tut/tut.html
        |
        | --
        | Garry Knight
        | garryknight@gmx .net ICQ 126351135
        | Linux registered user 182025


        Thanks for the information. At least you weren't rude about it.

        kbass


        Comment

        Working...