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

add indexes on the fly to lists

I wanted to make a list index work as the index of the data in the
database. something like

database:
idx
item_description
item_value

being imported to my program as:
x[idx][0]= item_description
x[idx][1]= item_value

the problem is that there will be some hundred items and possible the
idx wil vary from 1 to 600 (it's not linear as items got deleted the
idx should not be reused)

will it still be an easy solution or just a waste of resources (having
a 600-sized list for 100 elements)

I'm very new to python and apreciate any hints on that.

Thanks
Gabriel
Jul 18 '05 #1
3 1017
The data structure you want to use is a dictionary - known as hashmap or
hash or map in other languages. Lets say you have a few objects of type
town that you want to access using their zip, then things could look like
this:

------------
class Town(object):
def __init__(self, zip, cool_clubs):
self.zip = zip
self.colo_clubs = cool_clubs
towns = [Berlin(10439, ["Marietta", "ICON", "Bastart"]),
Cologne(50000, ["Subway", "Stadtgarten", "Gebäude 9"])]

index = {}
for town in towns:
index[town.zip] = town
----------------

Hope that makes it clear to you - look into the tutorial for a chapter about
python data structures.
--
Regards,

Diez B. Roggisch
Jul 18 '05 #2
Hi !

If you want only "search and found" element, look dictionnary ; if you want
also to have the order, see the module set.

Good night
--
Michel Claveau
Jul 18 '05 #3
> If you want only "search and found" element, look dictionnary ; if you
want also to have the order, see the module set.


Erg - no. Sets are mathematically defined as having no order.

--
Regards,

Diez B. Roggisch
Jul 18 '05 #4

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

Similar topics

0
by: Chris Edwards | last post by:
Hi Every night. I dump the schema of a table, drop it, create the table, and load it up with data. I'm using phpMyAdmin for the most part. I notice that the index cardinality shows up as None...
0
by: Jesse Sheidlower | last post by:
After some discussion in a separate thread, I've been trying to get a better understanding of the workings of multiple-column indexes, and think I'm still missing the point. I understand indexing...
1
by: Zack Sessions | last post by:
Still using SQL7. I am wondering how come there is not an Information_Schema view that lists indexes? Information_Schema is supposed to be the safest way to obtain information on metadata, but...
3
by: CSN | last post by:
In phppgadmin, primary keys are added/shown under "constraints". Does creating a primary key automatically create an index? No indexes are listed under phppgadmin's indexes page, but "\d table" in...
10
by: David Garamond | last post by:
Reading the archives and the FAQ, it seems to be implied that LIKE can use index (and ILIKE can't; so to do case-insensitive search you need to create a functional index on LOWER(field) and say:...
2
by: John Siracusa | last post by:
Are indexes useful for speeding up ORDER BY clauses? Example: CREATE TABLE t ( a INT, b INT, c INT, d INT );
4
by: Thomas F.O'Connell | last post by:
Since the current stable version of postgres (7.4.x) doesn't allow cross-datatype comparisons of indexes, is it always necessary to cast my application data explicitly in order for an index to be...
3
by: 001frien | last post by:
How do i find indexes of the columns of all the tables of the datbase...........most importantly in SQL server 2000 Thanks a lot
2
by: Gentr1 | last post by:
Hi everybody! I am presently working on a Genetic Programming API in python. I have a bit of a problem at the moment... For some specific reasons, I am using nested lists data structure to...
2
by: Vogon Jeltz | last post by:
Under SSMS where can one find the list of indices? I can see Stored procedures under Programmability. Is there any place where I can see the list of indexes. Apologies, if this is a stupid...
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
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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...
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)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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.