is this use of lists normal?

Gabriel B. gabriel.barros at
Tue Jan 25 02:30:24 CET 2005

I just sent an email asking for hints on how to import data into a
python program

As i said earlier i'm really new to python and besides being
confortable with the syntax, i'm not sure if i'm on the right track
with the logic

I'm asking for hints again here at the list because i think i'm
already into premature optimization...

My object model ended up as

|-itemsIndex (list, could very well be a set...)
|  |-[0] = 0
|  |-[1] = 1
|  |-[2] = 5
|  '-[3] = 6
'-Items (list)
   |-[0] = ['cat food', '12,20']
   |-[1] = ['dog food', 8,00']
   |-[2] = ['dead parrot', '25,00']
   '-[3] = ['friendly white bunny', '12,25']

the list itemsindex has the DB index of the data, and the list items
has the data.
So if i want something like "SELECT * FROM items WHERE idx=5" i'd use
in my program
self.items[ self.itemsIndex.index(5) ] 
i reccon that's not much nice to use when you're gona do /inserts/ but
my program will just read the entire data and never change it.

Was i better with dictionaries? the tutorial didn't gave me a good
impression on them for custom data...
Tupples? the tutorial mentions one of it's uses 'employee records from
a database' but unfortunatly don't go for it...

i think the 'ideal' data model should be something like
({'id': 0, 'desc': 'dog food', 'price': '12,20'}, ...)
But i have no idea how i'd find some item by the ID within it withouy
using some loops


More information about the Python-list mailing list