Why a dictionary? Why not a list of named tuples or a collection (list, dictionary) of objects from a class you define (with attributes for each column)?
What happened with:
class myRowObj(object): def __init__(self, mac, port, dpid): self.mac = mac self.port = port self.dpid = dpid myTable = list() for each in some_inputs: myTable.append(myRowObj(*each.split())
... or something like that?
(Note: myTable can be a list or a dictionary, or in any way that suits you. Obviously, if this is a dictionary, you should ask which key you will use to access these "lines").
The advantage of this approach is that your "string objects" (which you would name in some way, which would make more sense for your application domain) could implement any semantics that you choose. These objects can check and convert any values ββprovided when creating the instance, calculate any derived values, etc. You can also define the representation of the lines and codes of your object (implicit conversions, when one of your lines is used as a string or in certain types of development and debugging or serialization (for example, _str_ and _repr_ special methods).
Named tuples (added in Python 2.6) are a kind of lightweight object class that can offer some performance benefits and less memory space than regular user classes (for situations where you want named fields to not bind native methods to these objects, eg).
source share