-
Notifications
You must be signed in to change notification settings - Fork 0
/
Return Mismatched Words.py
90 lines (67 loc) · 2.24 KB
/
Return Mismatched Words.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import math
# Add any extra import statements you may need here
# Add any helper functions you may need here
def return_mismatched_words(str1, str2):
# Write your code here
str1_list = str1.split()
str2_list = str2.split()
list1 = [i for i in str1_list if i not in str2_list]
list2 = [i for i in str2_list if i not in str1_list]
return list1 + list2
# These are the tests we use to determine if the solution is correct.
# You can add your own at the bottom.
def printStringList(array):
size = len(array)
print('[', end='')
for i in range(size):
if i != 0:
print(', ', end='')
print(array[i], end='')
print(']', end='')
test_case_number = 1
def check(expected, output):
global test_case_number
expected_size = len(expected)
output_size = len(output)
result = True
if expected_size != output_size:
result = False
for i in range(min(expected_size, output_size)):
result &= (output[i] == expected[i])
rightTick = '\u2713'
wrongTick = '\u2717'
if result:
print(rightTick, 'Test #', test_case_number, sep='')
else:
print(wrongTick, 'Test #', test_case_number, ': Expected ', sep='', end='')
printStringList(expected)
print(' Your output: ', end='')
printStringList(output)
print()
test_case_number += 1
if __name__ == "__main__":
# Testcase 1
str1 = "Firstly this is the first string"
str2 = "Next is the second string"
output_1 = return_mismatched_words(str1, str2)
expected_1 = ["Firstly", "this", "first", "Next", "second"]
check(expected_1, output_1)
# Testcase 2
str1 = "This is the first string"
str2 = "This is the second string"
output_3 = return_mismatched_words(str1, str2)
expected_3 = ["first", "second"]
check(expected_3, output_3)
# Testcase 3
str1 = "This is the first string extra"
str2 = "This is the second string"
output_4 = return_mismatched_words(str1, str2)
expected_4 = ["first", "extra", "second"]
check(expected_4, output_4)
# Testcase 4
str1 = "This is the first text"
str2 = "This is the second string"
output_5 = return_mismatched_words(str1, str2)
expected_5 = ["first", "text", "second", "string"]
check(expected_5, output_5)
# Add your own test cases here