2017-02-17 6 views
0

、私はそれは、接続4ボードのように見えるので、sが全て消えている」角括弧のすべてのようにそれを作るとどうすればよいですか?次のコードを2D配列にするにはどうすればよいですか?また

Row7 = [" ","A","B","C","D","E","F","G"] 
Row6 = ["1","-","-","-","-","-","-","-"] 
Row5 = ["2","-","-","-","-","-","-","-"] 
Row4 = ["3","-","-","-","-","-","-","-"] 
Row3 = ["4","-","-","-","-","-","-","-"] 
Row2 = ["5","-","-","-","-","-","-","-"] 
Row1 = ["6","-","-","-","-","-","-","-"] 

board = [[Row7], [Row6], [Row5], [Row4], [Row3], [Row2], [Row1]] 

print (board) 

だから、可能であれば、私はそれはのようになりたいですこれ:

ABCDEFG

1 - - - - - - -

2 - - - - - - -

3 - - - - - - -

4 - - - - - - -

5 - - - - - - -

6 - - - - - - -

それはあまりにも2D配列である必要があります! 何か助けていただければ幸いです。

+0

をボードを宣言することができます。誰かがあなたのためにコードすることを期待することはできません。それはあなたが兄弟を習う方法です。 –

+0

私はnumpyを使って行を拡張しようとしましたが、うまく動作しないようです。 –

+0

正確に。あなたが試したことを知る必要があります。そのコードスニペットを説明に追加します。 –

答えて

0

あなたはただあなたがこれまでにしようとしているものを私たちに伝えるために必要な2次元配列(リストのリスト)として

board = [[" ","A","B","C","D","E","F","G"], 
     ["1","-","-","-","-","-","-","-"], 
     ["2","-","-","-","-","-","-","-"], 
     ["3","-","-","-","-","-","-","-"], 
     ["4","-","-","-","-","-","-","-"], 
     ["5","-","-","-","-","-","-","-"], 
     ["6","-","-","-","-","-","-","-"]] 
#or if you need the rows 
# Row7 is an list... so board will be a list of lists (2d array) 
# board = [Row7, Row6, Row5, Row4, Row3, Row2, Row1] 

def printB(board) : 
    for row in board: 
     print(" ".join(row)) 


printB(board) 


> A B C D E F G 
1 - - - - - - - 
2 - - - - - - - 
3 - - - - - - - 
4 - - - - - - - 
5 - - - - - - - 
6 - - - - - - - 
+0

ありがとうございました! –

関連する問題