-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcompress.py
26 lines (17 loc) · 962 Bytes
/
compress.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def distribution():
d={'A':0.08,'B':0.11,'C':0.23,'D':0.05,'E':0.07,'F':0.18,'G':0.02,'H':0.15,'I':0.01,'J':0.10}
return d
def spit():
"""This function will respect the distribution function and give you a
letter non-uniformly at random. Note that everytime you call this function,
it will just give you one letter (capital)."""
def create_file(n):
"""This function will create a file by name output.txt which will contain
letters picked respecting the given distribution. The file will have n
number of entries"""
def binary_encoding(d):
"""This will consider the dictionary d given to us by the function -
distribution. This function will output another dictionary b which stands
for encoding. For example b={'A':1001,'B':110,... and so on}. Note that you
only need to provide some encoding which is unambiguous. We dont want to
think of the best possible solution at this point of time. """