Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import wikipedia
- import sys
- def is_page_valid(page):
- try:
- wikipedia.page(page)
- except Exception:
- return False
- return True
- def lang(x):
- if x[len(x) - 1] not in wikipedia.languages():
- print('no results')
- sys.exit(0)
- else:
- wikipedia.set_lang(x[len(x) - 1])
- def summwords(x):
- maxim = 0
- title = ''
- for i in x:
- count = len(wikipedia.page(i).summary.split())
- if count >= maxim:
- maxim = count
- title = wikipedia.page(i).title
- print(maxim, title)
- def chain(x):
- res = []
- res.append(x[0])
- for i in range(0, len(x) - 1):
- link = wikipedia.page(x[i]).links
- if x[i + 1] in link:
- res.append(x[i + 1])
- else:
- for elem in link:
- if is_page_valid(elem):
- link1 = wikipedia.page(elem).links
- if x[i + 1] in link1:
- res.append(elem)
- res.append(x[i + 1])
- break
- print(res)
- a = input().split(', ')
- lang(a)
- a.pop(len(a) - 1)
- summwords(a)
- chain(a)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement