473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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
Jul 18 '05 #1
3 1578
On Tue, 16 Mar 2004 21:35:14 +0000, 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?

kbass


http://www.python.org/doc/current/tu...00000000000000
http://www.python.org/doc/current/lib/typesmapping.html

RTFM

Simon.

Jul 18 '05 #2
In message <mq******************@fe3.columbus.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
ga*********@gmx.net ICQ 126351135
Linux registered user 182025
Jul 18 '05 #3

"Garry Knight" <ga*********@gmx.net> wrote in message
news:10****************@lotis.uk.clara.net...
| In message <mq******************@fe3.columbus.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
| ga*********@gmx.net ICQ 126351135
| Linux registered user 182025
Thanks for the information. At least you weren't rude about it.

kbass
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Des Small | last post by:
Lately I have found myself using a pattern to make new dictionaries quite often, by which I mean twice: def invert(d): nd = {} ).append(key) for k, v in d] return nd def count(l): d = {}
2
by: kbass | last post by:
I am new to Python and I am attempting to retrieve data from a database and I would like to place this data into a nested dictionary. After placing the data into a dictionary, I would like to loop...
4
by: Edward Diener | last post by:
Version 2.0 of the Python database API was written over 5 years ago, in 1999. While it has been used successfully by many implementations, there is no generic access into the data dictionary of...
5
by: Lukas Holcik | last post by:
Hi everyone! How can I simply search text for regexps (lets say <a href="(.*?)">(.*?)</a>) and save all URLs(1) and link contents(2) in a dictionary { name : URL}? In a single pass if it could....
7
by: rickle | last post by:
I'm trying to compare sun patch levels on a server to those of what sun is recommending. For those that aren't familiar with sun patch numbering here is a quick run down. A patch number shows...
8
by: Rodd Snook | last post by:
I have an application which makes extensive use of the Scripting.Dictionary object. I'm not doing anything silly like putting them outside the page scope -- just creating quite a few of them and...
18
by: riftimes | last post by:
Hello, would you help me to find totorials with examples about generics and Dictionary thank you.
4
by: jansenh | last post by:
hi comp.lang.python. I need some newbe advice on idiomatic use of Python dictionaries. I have service with a dictionary which holds a bunch of objects as values, and an ID as key to each...
5
by: Bill Jackson | last post by:
What is the benefit of clearing a dictionary, when you can just reassign it as empty? Similarly, suppose I generate a new dictionary b, and need to have it accessible from a. What is the best...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.