Given an input string, write a function that returns the Run Length Encoded string for the input string.
For example, if the input string is ‘wwwwaaadexxxxxx’, then the function should return ‘w4a3d1e1x6’.
Input : str = 'wwwwaaadexxxxxx' Output : 'w4a3d1e1x6'
This problem has existing solution please refer Run Length Encoding link. Here we will solve this problem quickly in python using OrderedDict. Approach is very simple, first we create a ordered dictionary which contains characters of input string as key and 0 as their default value, now we run a loop to count frequency of each character and will map it to it’s corresponding key.
This article is contributed by Shashank Mishra (Gullu). If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Run Length Encoding
- Program to implement Run Length Encoding using Linked Lists
- Run Length Decoding in Linked List
- ML | Label Encoding of datasets in Python
- Python | C Strings of Doubtful Encoding | Set-2
- Python | C Strings of Doubtful Encoding | Set-1
- ML | One Hot Encoding of datasets in Python
- Python | Character Encoding
- Python | Encoding Decoding using Matrix
- Python - Golomb Encoding for b=2n and b!=2n
- response.encoding - Python requests
- Elias Gamma Encoding in Python
- Encoding and Decoding Base64 Strings in Python
- Encoding and Decoding Custom Objects in Python-JSON
- Run Python script from Node.js using child process spawn() method
- How to run Python code on Google Colaboratory
- Python | Making program run faster
- Run python script from anywhere in linux
- How to Run a Python Script
- Python | Longest Run of given Character in String
Improved By : gayatrivgk