-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_compression.py
More file actions
56 lines (42 loc) · 1.11 KB
/
check_compression.py
File metadata and controls
56 lines (42 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Given a string and a possible compression
# tell if that compression belongs to the string
def validate_compression(text, compression):
words = text.split(" ")
tokens = compression.split(" ")
if len(words) != len(tokens):
return False
words_to_tokens = {}
for i, word in enumerate(words):
current_token = tokens[i]
if word in words_to_tokens:
value_expected = words_to_tokens[word]
if current_token != value_expected:
print(f"Error with word {word} expected value {value_expected} found {current_token}")
return False
else:
words_to_tokens[word] = current_token
return True
A = ""
B = ""
#output: True
print(validate_compression(A, B))
A = "victor hugo pepe pepe victor"
B = "x h p p x"
# True
print(validate_compression(A, B))
A = "victor hugo pepe pepe victor"
B = "x h p p s"
# False
print(validate_compression(A, B))
A = "victor hugo pepe pepe victor"
B = "x h s p x"
# False
print(validate_compression(A, B))
A = "victor hugo pepe pepe victor"
B = ""
# False
print(validate_compression(A, B))
A = "victor hugo pepe pepe"
B = "x h s p x"
# False
print(validate_compression(A, B))