Trade-off in Python dictionary key types
Question: Say, I'm going to construct a probably large dictionary in Python 3 for in-
memory operations. The dictionary keys are integers, but I'm going to read
them from a file as string at first.

As far as storage and retrieval are concerned, I wonder if it matters whether
I store the dictionary keys as integers themselves, or as strings.  
In other words, would leaving them as integers help with hashing?


Answer: Dicts are fast but can be heavy on the memory. Normally it shouldn't be a
problem but you will only know when you test. I would advise to first test
1.000 lines, 10.000 lines and so on and have a look on the memory footprint.

If you run out of memory and your data structure allows it maybe try using
[named
tuples](https://docs.python.org/3/library/collections.html#collections.namedtuple).

    
    
    EmployeeRecord = namedtuple('EmployeeRecord', 'name, age, title, department, paygrade')
    import csv
    for emp in map(EmployeeRecord._make, csv.reader(open("employees.csv", "rb"))):
        print(emp.name, emp.title)
    

(Example taken from the link)

If you have ascending integers you could also try to get more fancy by using
the [array module](https://docs.python.org/3/library/array.html).

