Skip to content

Instantly share code, notes, and snippets.

@toenobu
Forked from yatt/vert.py
Last active December 15, 2015 00:49
Show Gist options
  • Save toenobu/5176033 to your computer and use it in GitHub Desktop.
Save toenobu/5176033 to your computer and use it in GitHub Desktop.
#! /usr/bin/python2.7
# coding: utf-8
target = u"""サンプルの文字列です。
Pythonで文字列を縦書きに
変換します。"""
lst = target.split()[::-1]
# mapで転置して結合
b = ["".join(map(lambda x:x if x != None else u" ", s)) for s in map(None, *lst)]
print "\n".join(b)
# 実行結果
"""
変Pサ
換yン
しtプ
まhル
すoの
。n文
 で字
 文列
 字で
 列す
 を。
 縦 
 書 
 き 
 に 
"""
@toenobu
Copy link
Author

toenobu commented Mar 16, 2013

clone元の人に、なにか飛んでたらごめんなさい。

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