I'm gathering data together in one part of my application and sending it off for work in another part. I've got a few thousand records, each containing an email address and a few ordered integers which represent some preferences.
My first thought was to organize my data in a dictionary like this:
{
"user1@domain.com": [23, 1, 5],
"user2@domain.com": [1, 4, 8]
}
But then I was thinking about tuples. I often overlook them, but tuples are a good option in Python, so I could do this:
[
("user1@domain.com", [23, 1, 5]),
("user2@domain.com", [1, 4, 8])
]
These examples show two records each, but I'll actually have somewhere in the low tens of thousands of records.
Is one of these more pythonic than the other? Is there another way I should consider?
I'm leaning towards the dictionary because when I build the structure I'm picking out ordered records that look like this:
(("user1@domain.com", 23), ("user1@domain.com", 1), ("user1@domain.com", 5), ("user2@domain.com", 1), ("user2@domain.com", 4), ("user2@domain.com", 8))
and combining them into one of the above forms. With the dictionary, it's easy to reference the same user's list over and over. With the list of tuples I guess I'd need to keep a reference to the last element, or keep calling len()
on the list.