2021-04-17から1日間の記事一覧
実用性はなさそうだが、勉強のために2次元配列を90度右回転させるには、 行単位で逆順に並べ替えて、行と列を入れ替えればいい。 >>> import pprint >>> a = [[1,2,3], [4,5,6], [7,8,9]] >>> pprint.pprint(a, width=20) [[1, 2, 3], [4, 5, 6], [7, 8, 9]]…
Python def display(data): for line in data: for ch in line: if ch: print('*', end='') else: print(' ', end='') print('') print('') a = [[0, 1, 1, 1, 1, 1, 1, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 0, 0, 0],…
Python str = ('A', 'C', 'K', 'S', 'T') stack1 = [] stack2 = [] stack3 = [] stack1.append(str[0]) stack2.append(str[1]) stack3.append(str[2]) stack1.append(str[3]) print(stack1.pop(), end="") stack1.append(str[4]) print(stack1.pop(), end=""…