Compressing a text file using count of continous characters

N

nirvana

I need to count the number of continous character occurances(more than
1) in a file, and replace it with a compressed version, like below
XYZAAAAAAAADEFAAcdAA --> XYZ8ADEF2Acd2A

Thanks
Sumod
 
M

Marc 'BlackJack' Rintsch

I need to count the number of continous character occurances(more than
1) in a file, and replace it with a compressed version, like below
XYZAAAAAAAADEFAAcdAA --> XYZ8ADEF2Acd2A

Great. Then go ahead an implement it. :)

`itertools.groupby()` might be handy.

And you have to think about digits in the source if that's allowed.

Ciao,
Marc 'BlackJack' Rintsch
 
C

Chris Mellon

I need to count the number of continous character occurances(more than
1) in a file, and replace it with a compressed version, like below
XYZAAAAAAAADEFAAcdAA --> XYZ8ADEF2Acd2A


This sounds like homework. Google for run length encoding for
algorithms, or check your textbook.
 
N

nirvana

This sounds like homework. Google for run length encoding for
algorithms, or check your textbook.

nah, not homework... :). And yeah got it. And thanks for its name
(RLE), that saved a lot of googles....

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top