Прикреплённый файл «PopularWord_gen.py»

Загрузка

   1 #!/usr/bin/env python3
   2 import urllib.request
   3 import sys
   4 from pathlib import Path
   5 import random
   6 
   7 URL = "https://github.com/first20hours/google-10000-english/raw/master/google-10000-english.txt"
   8 cache = Path("first20hours.o")
   9 if not cache.is_file():
  10     cache.write_bytes(urllib.request.urlopen(URL).read())
  11 words = cache.read_text().split()
  12 
  13 if len(sys.argv) > 1 and sys.argv[0].startswith("-"):
  14     print(f"Usage: {sys.argv[0]} words_number words_total is_single line_width")
  15     sys.exit(1)
  16 words_number = 20 if len(sys.argv) <= 1 else int(sys.argv[1])
  17 words_total = 300 if len(sys.argv) <= 2 else int(sys.argv[2])
  18 is_single = True if len(sys.argv) <= 3 else eval(sys.argv[3])
  19 line_width = 60 if len(sys.argv) <= 4 else int(sys.argv[4])
  20 
  21 vocabulary = random.sample(words, words_number)
  22 if is_single:
  23     text = random.choices(vocabulary, [words_number // 5] + [1] * (words_number - 1), k=words_total)
  24 else:
  25     swap = {vocabulary[0]: vocabulary[1], vocabulary[1]: vocabulary[0]}
  26     text = random.choices(vocabulary, [words_number // 5] + [1] * (words_number - 1), k=words_total // 2)
  27     text += [swap.get(s, s) for s in text]
  28 s = ""
  29 for w in text:
  30     if len(s) > line_width:
  31         print(s)
  32         s = w
  33     else:
  34         s += " " + w
  35 if s:
  36     print(s)
  37 print()

Прикреплённые файлы

Для ссылки на прикреплённый файл в тексте страницы напишите attachment:имяфайла, как показано ниже в списке файлов. Не используйте URL из ссылки «[получить]», так как он чисто внутренний и может измениться.
 Все файлы | Выбранные файлы: удалить переместить на страницу скопировать на страницу

Вам нельзя прикреплять файлы к этой странице.