[英]Trying to print the below Grid in Python
如果您對 python 外部包沒問題,這是一種方法
術語表: https://github.com/nschloe/termtables
!pip install termtables
import termtables as tt
string = "nevagonagiveu up"
# Python3 program to Split string into characters
def split(word):
return [char for char in word]
puzzle = split(string)
使用 numpy 轉換為二維數組
import numpy as np
puzzle_arr = np.array(puzzle).reshape(-1, 4)
puzzle_arr
grid = tt.to_string(
puzzle_arr,
style=tt.styles.ascii_thin,
# alignment="ll",
# padding=(0, 1),
)
print(grid)
Output:
+---+---+---+---+
| n | e | v | a |
+---+---+---+---+
| g | o | n | a |
+---+---+---+---+
| g | i | v | e |
+---+---+---+---+
| u | | u | p |
+---+---+---+---+
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.