Đoko, u skladu sa tvojom sugestijom,
nova verzija rečnika je na temi "Pravljenje englesko-srpskog rečnika".
Pogledaj, molim te, pa javi kako dalje.
Hvala unapred.
A ovde novi
zadatak broj 37:
# You have a text and a list of words. You need to check if the words in a list appear in the
# same order as in the given text.
# Cases you should expect while solving this challenge:
# word from the list is not in the text - your function should return False;
# any word can appear more than once in a text - use only the first one;
# two words are the same - your function should return False;
# the condition is case sensitive, which means 'hi' and 'Hi' are two different words.
# text includes only English letters and spaces
# Input: Two arguments. The first one is a given text, the second is a list of words.
# Output: A bool.
def words_order(text: str, words: list) -> bool:
# your code here
return False
if __name__ == '__main__':
print("Example:")
print(words_order('hi world im here', ['world', 'here']))
# These "asserts" are used for self-checking and not for an auto-testing
assert words_order('hi world im here', ['world', 'here']) == True
assert words_order('hi world im here', ['here', 'world']) == False
assert words_order('hi world im here', ['world']) == True
assert words_order('hi world im here', ['world', 'here', 'hi']) == False
assert words_order('hi world im here', ['world', 'im', 'here']) == True
assert words_order('hi world im here', ['world', 'hi', 'here']) == False
assert words_order('hi world im here', ['world', 'world']) == False
assert words_order('hi world im here', ['country', 'world']) == False
assert words_order('hi world im here', ['wo', 'rld']) == False
assert words_order('', ['world', 'here']) == False
Ja sam uradio nešto ovako:
Code:
import collections
def words_order(text: str, words: list) -> bool:
reci = text.split()
dic_text = dict(enumerate(reci))
dic_words = dict(enumerate(words))
indexi = []
for i in collections.Counter(words).values():
if i > 1:
return False
for i in dic_words.values():
for ind, rec in dic_text.items():
if i in rec:
indexi.append(ind)
indexi1 = sorted(indexi)
if indexi == indexi1:
return True
else:
return False
if __name__ == '__main__':
print("Example:")
print(words_order('hi world im here', ['world']))
ali mi javlja grešku na proveri
assert words_order('hi world im here', ['country', 'world']) == False
Nije mi jasno zašto to treba da bude False.
Kod mene je True, jer je jedina reč koja se javlja u tekstu, pa je time automatski redosled OK.