Skip to content

Instantly share code, notes, and snippets.

/1.py

Created September 2, 2016 18:51
Show Gist options
  • Save anonymous/5ce8e5d895ed8952fe4975c68e1b64c8 to your computer and use it in GitHub Desktop.
Save anonymous/5ce8e5d895ed8952fe4975c68e1b64c8 to your computer and use it in GitHub Desktop.
import re
import sys
from collections import deque
# удалить все пробелы
# 're que sts' -> 'requests'
s = re.sub(r'\s+', '', ''.join(sys.argv[1:]))
# https://ru.wikipedia.org/wiki/Двухсторонняя_очередь
# нужно для rotate, см. ниже
d = deque(s)
# проходит по каждому символу в строке, вращает деку на каждой итерации и join'ит результаты
# rotate(-1): requests -> equestr
# (join, rotate)[0] => join'им, вращаем и берем результат join'а
s = '\n'.join((' '.join(d), d.rotate(-1))[0] for _ in s)
print('[b]\n%s\n[/b]' % s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment