Created
August 20, 2012 23:27
-
-
Save mduheaume/3409226 to your computer and use it in GitHub Desktop.
compressing a bunch of id's to construct a url
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import base64 | |
import zlib | |
random_ids = [''.join([random.choice(string.ascii_lowercase) for x in range(8)]) for n in range(1000)] | |
long_string = ','.join(random_ids) | |
b64_string = base64.urlsafe_b64encode(long_string) | |
compressed_string = zlib.compress(long_string, 9) | |
b64_compressed_string = base64.urlsafe_b64encode(compressed_string) | |
len(long_string) | |
len(b64_string) | |
len(compressed_string) | |
len(b64_compressed_string) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment