LoginSignup
1
0

More than 5 years have passed since last update.

BLASTの結果っぽい文字列の表示

Last updated at Posted at 2012-12-26

試しに。
複数の同じ長さの文字列を並べて表示したい時のための方法。BLASTなどの結果と似た感じの出力。

from math import ceil

hoge = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
fuga = "abcdefghijklmnopqrstuvwxyz"

def multi_line(str_list, col_length):
    # str_list内の文字列の長さは同じとする
    for k in range(int(ceil((float(len(str_list[0])))/col_length))):
        e = (k + 1)*col_length if (k+1)*col_length < len(str_list[0]) else len(str_list[0])
        for s in str_list:
            print s[k*col_length:e]
        print "\n"

multi_line([hoge, fuga], 13)
# This will produce:
# ABCDEFGHIJKLM
# abcdefghijklm
#
# NOPQRSTUVWXYZ
# nopqrstuvwxyz
#
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0