Skip to content

Instantly share code, notes, and snippets.

@shiumachi
Created January 7, 2014 15:53
Show Gist options
  • Save shiumachi/8301406 to your computer and use it in GitHub Desktop.
Save shiumachi/8301406 to your computer and use it in GitHub Desktop.
文字列のリストを与えたとき、要素内の最大長の文字列に合わせて右寄せで出力する
def print_arr_right_aligned(arr):
""" input: string array ['a', 'ab', 'abc']
output: None. print with right aligned.
a:
ab:
abc:
"""
len_a = max(map(lambda x: len(x), arr))
for i in arr:
print("{0:>{1}}: ".format(i, len_a))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment