Python 实现二维数组
Python# -*- coding: utf-8 -*-"""@Time: 2018/4/12@Author: songhao@微信公众号: zeropython@File: grid.py"""from .ar...
·
# -*- coding: utf-8 -*- """ @Time: 2018/4/12 @Author: songhao @微信公众号: zeropython @File: grid.py """ from .arrays import Array class Grid: def __init__(self,rows,colums,fillvalue = None): self._data = Array(rows) for row in range(rows): self._data[row] = Array(colums,fillvalue) def get_heigh(self): return str(self._data) def get_weight(self): return str(self._data[0]) def __getitem__(self, index): return self._data[index] def __str__(self): result = '' for row in range(self.get_heigh()): for col in range(self.get_weight()): result += str(self._data[row][col]) + "" result += '\n'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# -*- coding: utf-8 -*-
"""
@Time: 2018/4/12
@Author: songhao
@微信公众号: zeropython
@File: grid.py
"""
from . arrays import Array
class Grid :
def __init__ ( self , rows , colums , fillvalue = None ) :
self . _data = Array ( rows )
for row in range ( rows ) :
self . _data [ row ] = Array ( colums , fillvalue )
def get_heigh ( self ) :
return str ( self . _data )
def get_weight ( self ) :
return str ( self . _data [ 0 ] )
def __getitem__ ( self , index ) :
return self . _data [ index ]
def __str__ ( self ) :
result = ''
for row in range ( self . get_heigh ( ) ) :
for col in range ( self . get_weight ( ) ) :
result += str ( self . _data [ row ] [ col ] ) + ""
result += '\n'
|
更多推荐
所有评论(0)