473,387 Members | 1,464 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,387 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 3058

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: 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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.