Python 得到一个“sub”来自更大的二维列表的二维列表?
如何从更大的 2d 列表中获取 2d 子列表?
gridx = 10
gridy = 16
grid = [[0]*gridx for i in range(gridy)]
subgrid = None
# I want to get a subgrid given an x,y grid origin (bottom-left) and x,y subgrid size
How would you get a 2d sublist from a bigger 2d list?
gridx = 10
gridy = 16
grid = [[0]*gridx for i in range(gridy)]
subgrid = None
# I want to get a subgrid given an x,y grid origin (bottom-left) and x,y subgrid size
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想在限制 x1、y1、x2、y2 处对 2D 列表进行切片,您可以这样做:
例如:
If you want to slice your 2D list at the limits x1, y1, x2, y2 you can do:
for example:
我假设您的网格存储在列表列表中?也就是说:
如果是这样,您的答案是从起点到终点遍历这些列表。
I assume your grid is stored in a list of lists? That is:
If so, your answer is a walk across these lists, from your start point, to your endpoint.