performance question: dictionary or list, float or string?

bkamrani at gmail.com bkamrani at gmail.com
Tue Dec 2 06:51:55 EST 2008


I forgot to mention that I did a simple timeit test which doesn't
show
significant runtime difference 3.5 sec for dictionary case and 3.48
for
list case.


def read_as_dictionary():
    fil = open('myDataFile', 'r')
    forces = {}
    for region in range(25):
        forces[region] = {}

    for step in range(20000):
        for region in range(25):
            line = fil.next(); spl = line.split()
            forces[region] [step] = spl

def read_as_list():
    fil = open('myDataFile.txt', 'r')
    forces = []
    for region in range(25):
        forces.append([])

    for step in range(20000):
        for region in range(25):
            line = fil.next(); spl = line.split()
            forces[region].append(spl)

Cheers,
/Ben




More information about the Python-list mailing list