二维列表取值
class Vector2:
"""
向量
"""
def __init__(self, x=0, y=0):
self.x = x
self.y = y
@staticmethod
def right():
return Vector2(0, 1)
@staticmethod
def up():
return Vector2(-1, 0)
@staticmethod
def lift():
return Vector2(0, -1)
@staticmethod
def down():
return Vector2(1, 0)
@staticmethod
def right_up():
return Vector2(-1, 1)
class DoubleListHelper:
"""
二维列表助手类
"""
@staticmethod
def get_elements(list_target, v_pos, v_dir, count):
result = []
for i in range(count):
v_pos.x += v_dir.x
v_pos.y += v_dir.y
result.append(list_target[v_pos.x][v_pos.y])
return result
list01 = [
["00", "01", "02", "03"],
["10", "11", "12", "13"],
["20", "21", "22", "23"],
]
re01 = DoubleListHelper.get_elements(list01,Vector2(1,0),Vector2.right(),3)
print(re01)