import wikipedia
def IsLanguageExistInWikipedia(language):
if language in wikipedia.languages():
return True
else:
return False
def LanguageSetup(language):
if IsLanguageExistInWikipedia(language):
wikipedia.set_lang(language)
else:
return False
def CountWordsInPage(page):
return len(page.summary.split())
def MaximumCountWordsOnPagesAndTitle(names):
maximum = -1
title = ""
for name in names:
count = CountWordsInPage(wikipedia.page(name))
if count >= maximum:
maximum = count
title = name
return f"{maximum} {title}"
def IsPageAvailable(name):
try:
wikipedia.page(name)
except Exception:
return False
return True
def CreateChain(names):
chain = [names[0]]
for index in range(len(names) - 1):
page = wikipedia.page(names[index])
if names[index + 1] in page.links:
chain.append(names[index + 1])
else:
for link in page.links:
if not IsPageAvailable(link):
continue
intermediate = wikipedia.page(link)
if names[index + 1] in intermediate.links:
chain.append(intermediate.title)
chain.append(names[index + 1])
break
return(chain)
input = ['Чуумпу далай', 'Хоту Америка', 'Континент', 'sah']
# input = input().split(', ')
if not IsLanguageExistInWikipedia(language):
print('no results')
else:
LanguageSetup(input[-1])
print(MaximumCountWordsOnPagesAndTitle(input[0:-1]))
print(CreateChain(input[0:-1]))
if not IsLanguageExistInWikipedia(language):
print('no results')
if not IsLanguageExistInWikipedia(language):
print('no results')