Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def decompression(str):
- # @param str : string (compressa)
- # @return string (str decompressa)
- res=''
- for i in range(0,len(str)):
- char=str[i]
- if char.isdigit():
- res=res+(int(char)-1)*str[i+1]
- else:
- res=res+char
- return res
- def compression(str):
- # @param str : string (decompressa e composta esclusivamente da caratteri alfabetici)
- # @return string (str compressa)
- res=''
- count=1
- for i in range(0,len(str)):
- char=str[i]
- if char==str[min(i+1,len(str)-1)]:
- if i==len(str)-1 and count!=2 and count!=1:
- res=res+repr(count)+char
- return res
- elif i==len(str)-1 and count==2:
- res=res+count*char
- return res
- elif i==len(str)-1 and count==1:
- res=res+char
- return res
- count=count+1
- elif char!=str[min(i+1,len(str)-1)] and count!=2 and count!=1:
- res=res+repr(count)+char
- count=1
- elif count==2:
- res=res+count*char
- count=1
- elif count==1:
- res=res+char
- return res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement