473,545 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
+ 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:zi p 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,2 4)+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("cre ate table 'table1' ('name' text(20), 'address'
text(100), primary key ('name', 'address'))")
...[110]: <sqlite3.Curs or object at 0x2b0cd9712c38>
>>>[111]: db.executemany( "insert into 'table1' values (?, ?)",
((letters[i%len(letters)]*i, "%d street" % i) for i in range(1000))).r owcount
...[111]: 1000
>>>[112]: for i in db.execute("sel ect * from 'table1' where address
like '99 %'") : print i
.....:
(u'VVVVVVVVVVVV VVVVVVVVVVVVVVV VVVVVVVVVVVVVVV VVVVVVVVVVVVVVV VVVVVVVVVVVVVVV VVVVVVVVVVVVVVV VVVVVVVVVVVV',
u'99 street')
>>>[113]: for i in db.execute("sel ect * from 'table1' where name
like '___'") : print i
.....:
(u'ddd', u'3 street')
>>>[114]: db.execute("ins ert into 'table1' values (?, ?)", ('ddd', '4
street')).rowco unt
...[114]: 1
>>>[115]: for i in db.execute("sel ect * from 'table1' where name
like '___'") : print i
.....:
(u'ddd', u'3 street')
(u'ddd', u'4 street')
>>>[116]: db.execute("ins ert into 'table1' values (?, ?)", ('ddd', '4
street')).rowco unt
---------------------------------------------------------------------------
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 3078

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

Similar topics

2
10636
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: imageID image_order I want to be able to modify the image_order column where imageID = imageID.
66
4909
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
13209
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: Hunter_69. Here is what the form looks like. I have the difficulty of inserting the multiple items selected by the user the first time he visits and uses...
10
3208
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 into another table on a remote server. The below code only inserts 1 record. How do I change the code to get all records inserted? thanks! <% Dim...
1
2540
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 above questions by using .NET but I think it can be more efficient by using just SQL. I would appreciate if you can give me an answer. Thank you.
4
2552
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 multiple records and want two values depending on the row they select. slaveform: x=selected
3
6012
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. Menu.userGroupID has multiple values seperated by commas. User.userGroupID also has multiple values seperated by commas. I realize some may want me to...
16
17383
by: Nikolay Petrov | last post by:
How can I return multiple values from a custom function? TIA
10
6358
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: dropdownlist.items.findbyvalue("value").selected = true I didnt specify any selected item in the dropdownlist during binding to the datasource. I use dropdownlist.clearselection() but...
8
5186
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 more than one value, for example three int-s, I would have to change my "logic" and pass the references to my
0
7490
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7425
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7449
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7780
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6009
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5351
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5069
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3465
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.