Created
March 14, 2013 16:29
-
-
Save yatt/5162824 to your computer and use it in GitHub Desktop.
文字列の縦書き変換
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python2.7 | |
# coding: utf-8 | |
target = u"""サンプルの文字列です。 | |
Pythonで文字列を縦書きに | |
変換します。""" | |
lst = target.split()[::-1] | |
# 全角スペースをパディング | |
lst = [s.ljust(len(max(lst)), ' ') for s in lst] | |
# zipで転置して結合 | |
v = '\n'.join(''.join(s) for s in zip(*lst))) | |
print v | |
# 実行結果 | |
""" | |
変Pサ | |
換yン | |
しtプ | |
まhル | |
すoの | |
。n文 | |
で字 | |
文列 | |
字で | |
列す | |
を。 | |
縦 | |
書 | |
き | |
に | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
昔、縦書きはそれなりに研究したわ。知り合いと楽しむために文章に入れたりね。