473,479 Members | 2,117 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 3063

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

Similar topics

2
10632
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
4896
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
13202
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
3198
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
2531
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
2537
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
6004
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
17366
by: Nikolay Petrov | last post by:
How can I return multiple values from a custom function? TIA
10
6341
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
5161
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
7033
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6903
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7071
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...
1
6726
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5318
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4468
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2987
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1291
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
557
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.