tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
9
Task/Run-length-encoding/Python/run-length-encoding-2.py
Normal file
9
Task/Run-length-encoding/Python/run-length-encoding-2.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
from itertools import groupby
|
||||
def encode(input_string):
|
||||
return [(len(list(g)), k) for k,g in groupby(input_string)]
|
||||
|
||||
def decode(lst):
|
||||
return ''.join(c * n for n,c in lst)
|
||||
|
||||
encode("aaaaahhhhhhmmmmmmmuiiiiiiiaaaaaa")
|
||||
decode([(5, 'a'), (6, 'h'), (7, 'm'), (1, 'u'), (7, 'i'), (6, 'a')])
|
||||
Loading…
Add table
Add a link
Reference in a new issue