Skip to content

Instantly share code, notes, and snippets.

@yatt
Created March 14, 2013 16:29
Show Gist options
  • Save yatt/5162824 to your computer and use it in GitHub Desktop.
Save yatt/5162824 to your computer and use it in GitHub Desktop.
文字列の縦書き変換
#! /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文
 で字
 文列
 字で
 列す
 を。
 縦 
 書 
 き 
 に 
"""
@sou1
Copy link

sou1 commented Jan 29, 2015

昔、縦書きはそれなりに研究したわ。知り合いと楽しむために文章に入れたりね。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment