1
0
Fork 0
Python2017/labs02/task03.py

37 lines
1.1 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Zad 4. Napisz funkcje oov(text, vocab), która zwraca listę wyrazów
(bez duplikatów), które występują w tekście text i nie występują w liście
znanych wyrazów vocab. Argumenty funkcji text i vocab to odpowiednio łańcuch
znakowy i lista łańuchów znakowych. Wszystkie wyrazy należy zmienić na małe
litery. (OOV = out of vocabulary) (W pythonie istnieje struktura danych tak
jak 'set', która przechowuje elementy bez powtórzeń.)
"""
def oov(text, vocab):
text = text.split()
result = [char for char in text if char not in vocab]
result = sorted(set(result))
return result
def tests(f):
inputs = [("this is a string , which i will use for string testing",
[',', 'this', 'is', 'a', 'which', 'for', 'will', 'i'])]
outputs = [['string', 'testing', 'use']]
for input, output in zip(inputs, outputs):
if set(f(*input)) != set(output):
return "ERROR: {}!={}".format(f(*input), output)
break
return "TESTS PASSED"
if __name__ == "__main__":
print(tests(oov))