Last active
February 23, 2018 06:21
-
-
Save inakagawa/da63ed10429eed67be1822718b3bea62 to your computer and use it in GitHub Desktop.
テキストをブロックで切り、インデントをつけて出力する:w
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
chunk = """ | |
quick | |
brown | |
foxes | |
jumped | |
over | |
the lazy dog | |
""" | |
# read, readlines | |
block_lines=[] | |
buff = [] | |
alldata = [] | |
# 雑にグループ化する | |
# 改行連続で切る | |
# 空のグループを除外する | |
rough_blocks = list(filter(lambda x: x != "", chunk.split("\n\n"))) # \n切りを明示→空行も含める | |
# for l in sys.stdin.readlines(): | |
for bl in rough_blocks: | |
# filter() returns <filter> | |
lines = list(filter(lambda x: x != "", bl.split("\n"))) | |
if lines != []: | |
block_lines.append(lines) | |
# function libs | |
# 2要素目以降に、インデントスペースを設ける | |
def indent_second(lines): | |
newlines = list(map(lambda x: " " + x, lines)) | |
newlines[0] = newlines[0].strip() | |
return newlines | |
result = list(map(indent_second, block_lines)) | |
# output | |
output=[] | |
for arr in result: | |
output.extend(arr) | |
for l in output: | |
print(l) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment