473,325 Members | 2,774 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,325 software developers and data experts.

Re: Multiple values for one key

Le Thursday 28 August 2008 03:43:16 norseman, vous avez écrit*:
Terry Reedy wrote:
Ron Brennan wrote:
Hello,
How would I create a dictionary that contains multiple values for one
key.
Make the value a collection object (set or list if you plan to add and
delete).
I'd also like the key to be able to have duplicate entries.
Dict keys must be hashable and unique.

tjr

--
http://mail.python.org/mailman/listinfo/python-list

================
First part I understand, second is still giving me a problem.

For some reason I still want keys to be dbf column headers.
like:

name:address:zip so forth
---- ------- --- ------------------
guy: unknown:00000
girl: 123 tiny street:12345
boy:321 here:33333
gal:999 over there: 55555
so forth

Thus one key has many values. And you can then index on whatever key(s)
you wish - name,zip...

With billions plus records, trying to put a unique key on each entry
seems to preclude the need for a dictionary, just use the entries.
(Format to SDF and index on substr(line,1,24)+substr(line,48,+5) etc..)
name + zip
OK - I know I missed the whole concept of a Python Dictionary. I haven't
read anything as yet that gives a clear picture of what it is and what
it is for. Please, classroom concepts usually consist of a handful of
objects. I have files here that takes up multiple DVDs each, AFTER a 15
to 1 compression. 3 bytes per pixel. I need to work with them. Things
like changing geobase projections and cookie cutting based on real world
coordinates and modifying the lumens and so forth. Based on what I've
read, the Python Dictionary concept flat will not work for such as this.
Yes - the example is overkill. But in my world it is reality. I deal
with sizeable things. Not all are raster. Most all are binary! Things
that work on massive text files - like banking and mortgage - simply
don't work here. There are seldom 'lines'. There are always bytes. Lots
of bytes. Things that form a group are not necessarily stored sequentially.

Back to What Is A Python Dictionary: Somebody please enlighten me.

Disctionaries are hash tables with a unique key and constant time lookup. What
you want could be implemented as a complex data structures with as many dict
as needed keys, but it seems you really want a relational table and a rdbms.
This is exactly what they are for. A short example with the new python2.5
sqlite package :
>>>[107]: import sqlite3
>>>[108]: from string import letters
>>>[109]: db = sqlite3.connect(':memory:')
>>>[110]: db.execute("create table 'table1' ('name' text(20), 'address'
text(100), primary key ('name', 'address'))")
...[110]: <sqlite3.Cursor object at 0x2b0cd9712c38>
>>>[111]: db.executemany("insert into 'table1' values (?, ?)",
((letters[i%len(letters)]*i, "%d street" % i) for i in range(1000))).rowcount
...[111]: 1000
>>>[112]: for i in db.execute("select * from 'table1' where address
like '99 %'") : print i
.....:
(u'VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV VV',
u'99 street')
>>>[113]: for i in db.execute("select * from 'table1' where name
like '___'") : print i
.....:
(u'ddd', u'3 street')
>>>[114]: db.execute("insert into 'table1' values (?, ?)", ('ddd', '4
street')).rowcount
...[114]: 1
>>>[115]: for i in db.execute("select * from 'table1' where name
like '___'") : print i
.....:
(u'ddd', u'3 street')
(u'ddd', u'4 street')
>>>[116]: db.execute("insert into 'table1' values (?, ?)", ('ddd', '4
street')).rowcount
---------------------------------------------------------------------------
IntegrityError Traceback (most recent call last)

/home/maric/<ipython consolein <module>()

IntegrityError: columns name, address are not unique
>
Steve
no******@hughes.net
--
http://mail.python.org/mailman/listinfo/python-list


--
_____________

Maric Michaud
Aug 28 '08 #1
0 3047

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

Similar topics

2
by: scott | last post by:
Hi, I'm having some trouble with something that should be relatively easy. I want to update multiple rows in one of my database tables simultaneously. In my table I have these values: ...
66
by: Darren Dale | last post by:
Hello, def test(data): i = ? This is the line I have trouble with if i==1: return data else: return data a,b,c,d = test()
3
by: jason | last post by:
How does one loop through the contents of a form complicated by dynamic construction of checkboxes which are assigned a 'model' and 'listingID' to the NAME field on the fly in this syntax:...
10
by: shank | last post by:
I have a recordset that contains multiple records of product a user is purchasing. For clarity, I converted the recordset fields to variables. I need to take that entire recordset and insert it...
1
by: John Smith | last post by:
I have a user assigned multiple roles and a role can be inherited from multiple parents (see below). How do I answer such questions as "How many roles does the user belongs to?" I answered the...
4
by: cwwilly | last post by:
Hello, Thanks for taking a look at this! Problem: I'm trying to pass multiple dynamic values between a slaveform and a masterform. The problem I'm having is on the slaveform I loop through...
3
by: rhamlin | last post by:
I'm fairly new to creating complex sql statements and need a little help. In plain english I want to do this: Select menu rows where the row's userGroupIDs equal the user's userGroupIDs. ...
16
by: Nikolay Petrov | last post by:
How can I return multiple values from a custom function? TIA
10
by: ads | last post by:
hi, after binding the dropdownlist to a datasource, ive experience this error "Cannot have multiple items selected in a dropdownlist" after using the code:...
8
by: aleksandar.ristovski | last post by:
Hello all, I have been thinking about a possible extension to C/C++ syntax. The current syntax allows declaring a function that returns a value: int foo(); however, if I were to return...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.