Jan-22-2018, 04:19 AM
there's zlib:
import zlib class TryZlibBz2: def __init__(self): your_text = str.encode('i am looking for some already existing implementation of this logic i am ready to implement for myself, if necessary. i want to "compact" a mutable sequence by removing duplicates, keeping the order of both the unique items and each first item of duplicates. converting to a set loses the original order, so it is not an option to convert to a set and convert back, but maybe a set can be used to help detect duplicates in an implementation. anyone know of an existing implementation?') compressed = self.zlib_encode(your_text) print(f'orig len: {len(your_text)}, len compressed: {len(compressed)}') print(f'\n{self.zlib_decode(compressed).decode()}') def zlib_encode(self, text): return zlib.compress(text) def zlib_decode(self, enctext): return zlib.decompress(enctext) if __name__ == '__main__': TryZlibBz2()results:
Output:orig len: 484, len compressed: 263
i am looking for some already existing implementation of this logic i am ready to implement for myself, if necessary. i want to "compact" a mutable sequence by removing duplicates, keeping the order of both the unique items and each first item of duplicates. converting to a set loses the original order, so it is not an option to convert to a set and convert back, but maybe a set can be used to help detect duplicates in an implementation. anyone know of an existing implementation?