Python Forum
compacting a mutable sequence
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
compacting a mutable sequence
#2
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?
Reply


Messages In This Thread
compacting a mutable sequence - by Skaperen - Jan-22-2018, 03:44 AM
RE: compacting a mutable sequence - by Larz60+ - Jan-22-2018, 04:19 AM
RE: compacting a mutable sequence - by Skaperen - Jan-22-2018, 06:17 AM
RE: compacting a mutable sequence - by Gribouillis - Jan-22-2018, 06:29 AM
RE: compacting a mutable sequence - by Skaperen - Jan-22-2018, 06:46 AM
RE: compacting a mutable sequence - by Gribouillis - Jan-22-2018, 06:54 AM
RE: compacting a mutable sequence - by Skaperen - Jan-23-2018, 03:54 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  using mutable in function defintion as optional paramter akbarza 8 785 Apr-27-2024, 09:59 PM
Last Post: snippsat
  mutable argument in function definition akbarza 1 628 Dec-15-2023, 02:00 PM
Last Post: deanhystad
  mutable values to string items? fozz 15 3,352 Aug-30-2022, 07:20 PM
Last Post: deanhystad
  "'DataFrame' objects are mutable, thus they cannot be hashed" Mark17 1 7,117 Dec-25-2020, 02:31 AM
Last Post: tinh
  Mutable Strings millpond 3 2,782 Aug-24-2020, 08:42 AM
Last Post: millpond
  What is the meaning of mutable data type? qliu 3 3,153 Apr-17-2020, 07:20 PM
Last Post: deanhystad
  copying parts of mutable sequences Skaperen 1 2,357 Dec-02-2019, 10:34 AM
Last Post: Gribouillis
  A mutable string?? silentknight85 5 4,898 May-31-2019, 10:11 AM
Last Post: silentknight85
  compacting multiple ranges Skaperen 2 3,219 Oct-11-2017, 08:33 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020