473,490 Members | 2,458 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

need optimizing help

I have a dictionary with a very very large(possibly millions) of
key/value pairs.
The key is a tuple that looks like (id,date)
What is the fastest way to get out all of the values that match any
key given that they individual key elements are coming from two
seperate lists?
The approach of
for id in IDS:
for date in dates:
data=myDict[(id,date)]

seems to just take too long. Is there a speedier, more pythonic, way
of doing this? Any help speeding this up would be much appreciated!!
Jul 18 '05 #1
3 1033
On Sat, 13 Mar 2004 10:07:54 -0800, rabbits77 wrote:
I have a dictionary with a very very large(possibly millions) of
key/value pairs.
The key is a tuple that looks like (id,date)
What is the fastest way to get out all of the values that match any
key given that they individual key elements are coming from two
seperate lists?
The approach of
for id in IDS:
for date in dates:
data=myDict[(id,date)]

seems to just take too long. Is there a speedier, more pythonic, way
of doing this? Any help speeding this up would be much appreciated!!


if IDS and dates lenght is the same, you could write
for i in enumerate(IDS):
data=myDict[(IDS[i],dates[i])]

which is more good looking, but I think performances are similar.

my 2 cents.

Riccardo
Jul 18 '05 #2
In article <68*************************@posting.google.com> ,
rabbits77 <ra*******@bigmailbox.net> wrote:

I have a dictionary with a very very large(possibly millions) of
key/value pairs.


If it's literally millions, you probably want to use a database. Just
the dictionary itself (not even talking about the objects used for keys
and values) will take at least 12MB per million entries on a machine with
32-bit addresses.
--
Aahz (aa**@pythoncraft.com) <*> http://www.pythoncraft.com/

"usenet imitates usenet" --Darkhawk
Jul 18 '05 #3
rabbits77 <ra*******@bigmailbox.net> wrote:
I have a dictionary with a very very large(possibly millions) of
key/value pairs.
The key is a tuple that looks like (id,date)
What is the fastest way to get out all of the values that match any
key given that they individual key elements are coming from two
seperate lists?
The approach of
for id in IDS:
for date in dates:
data=myDict[(id,date)]

seems to just take too long. Is there a speedier, more pythonic, way
of doing this? Any help speeding this up would be much appreciated!!


Hmm... since you're looking up every possible combination of 'id' and
'date', there is no short cut of algorithm. As for speed, it may be
faster to use external database.

--
William Park, Open Geometry Consulting, <op**********@yahoo.ca>
Linux solution for data processing and document management.
Jul 18 '05 #4

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

Similar topics

6
2857
by: A Future Computer Scientist | last post by:
A question: Is it really important to think about optimizing the native code or optimizing it for P Code? Or does the code you write make a difference?
16
2235
by: JustSomeGuy | last post by:
I have a routine that evaluates a polynomial equation that have 3 variables x,y,z of orders 1,2,3 the coefficients of the polynomial are in an array. This routine is quite slow and I'd like to...
5
3517
by: ArShAm | last post by:
Hi there Please help me to optimize this code for speed I added /O2 to compiler settings I added /Oe to compiler settings for accepting register type request , but it seems that is not allowed...
35
8288
by: Thomas Matthews | last post by:
Hi, My son is writing a program to move a character. He is using the numbers on the keypad to indicate the direction of movement: 7 8 9 4 5 6 1 2 3 Each number has a direction except...
31
2584
by: mark | last post by:
Hello- i am trying to make the function addbitwise more efficient. the code below takes an array of binary numbers (of size 5) and performs bitwise addition. it looks ugly and it is not elegant...
2
1542
by: Brian | last post by:
In particular, this question goes out to the Microsoft C++ development team. Back in June, Ronald Laeremans posted the following message. Has the optimizing compiler been included with the...
4
1459
by: Flashman | last post by:
A little confusing with setting up optimizing options with 2003 .NET. Under the Optimization Tab. if you set to /O1 or /O2 is the program ignoring the settings for Inline Function expansion,...
4
3474
by: Got2Go | last post by:
Hello Group, I have a table that has millions of records in it. About 100 records are added every 5 minutes (one per OIDID) (the sample provided below has data for 2 OIDIDs (99 and 100) And I...
12
3064
by: Mark E. Fenner | last post by:
Hello all, I have a code where my inner loop looks like: allNew = for params in cases: newObj = copy(initialObject) newObj.modify(params) allNew.append(newObj) return allNew
8
2370
by: rshivaraman | last post by:
Hi : I have a TableA with around 10 columns with varchar and numeric datatypes It has 500 million records and its size is 999999999 KB. i believe it is kb i got this data after running...
0
7108
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
6967
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
7142
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
7181
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
6847
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
7352
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...
0
5445
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,...
1
4875
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...
1
618
muto222
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.