Is there a way to reversibly compress a tuple of integers in Python? I have a large number of 5 digit tuples (values range from 0-100000) that I want to be able to store in a more memory efficient way but I also need to use their original values at a later point.
If I had a tuple like this:
test_tuple = (520, 203, 9721, 12, 4839)
I'd like to be able to compress it to a single integer value, similar to pythons default hash function, except I need to be able to recreate the tuple from the integer value, which is not possible with the hash function.
So something like:
compressed = compress(test_tuple)
og_tuple = decompress(compressed)
Where compressed is an integer (or other small memory) representation of test_tuple and og_tuple is the original tuple extracted from the compressed representation. Ideally the solution should also be fast.