Skip to content

Commit 4a30b50

Browse files
author
Dan Finn
committed
run length encoding exercise
1 parent fe4fba6 commit 4a30b50

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed
File renamed without changes.

run_length_encoding.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/python
2+
from collections import OrderedDict
3+
4+
input = raw_input("Please enter in some text to be compressed: ")
5+
6+
def runlengthencode(input):
7+
dict=OrderedDict.fromkeys(input,0)
8+
9+
for char in input:
10+
dict[char] += 1
11+
12+
output=''
13+
for k,v in dict.iteritems():
14+
output = output + k + str(v)
15+
return output
16+
17+
print runlengthencode(input)

0 commit comments

Comments
 (0)