Python:将嵌套列表转换为具有坐标位置的简单列表
我目前正在学习 python 和 panda3d。 我有一个嵌套列表,需要将其转换为坐标列表。
我的输入是
[['g,g', 'g,g'], ['d,d', 'd,d,d', 'd,d], ['s,s', 's,s']]
我需要的输出是另一个列表:
[(0,0,0,'s'),(0,1,0,'s'),(1,0,0,'s'),(1,1,0,'s'),(0,0,1,'d'),(0,1,1,'d'),(1,0,1,'d'),(1,1,1,'d'),(1,2,1,'d'),(2,0,1,'d'),(2,1,1,'d'),(0,0,2,'g'),(0,1,2,'g'),(1,0,2,'g'),(1,1,2,'g')]
这个简单的列表转换正在扰乱我的大脑。 o.0
编辑:更多信息: 在输入列表中,最后一个嵌套列表代表基础层。
这个想法是将我在文件中写入的字符串转换为坐标点。这是文件的内容:
[LVL02]
g,g
g,g
[/LVL02]
[LVL01]
d,d
d,d,d
d,d
[/LVL01]
[LVL00]
s,s
s,s
[/LVL00]
这应该给我一个非常基本的地图制作器。每个级别都是一个平坦的二维表面。
[LVL02]
g,g (0,0,2,'g'),(0,1,2,'g')
g,g (1,0,2,'g'),(1,1,2,'g')
[/LVL02]
[LVL01]
d,d (0,0,1,'d'),(0,1,1,'d')
d,d,d (1,0,1,'d'),(1,1,1,'d'),(1,2,1,'d')
d,d (2,0,1,'d'),(2,1,1,'d')
[/LVL01]
[LVL00]
s,s (0,0,0,'s'), 0,1,0,'s')
s,s (1,0,0,'s'),(1,1,0,'s')
[/LVL00]
IE。 (x 轴、y 轴、z 轴、类型)
I am learning python and panda3d currently.
I have a nested list which i need to convert into a list of coordinates.
my input is
[['g,g', 'g,g'], ['d,d', 'd,d,d', 'd,d], ['s,s', 's,s']]
The Output that I need is another list:
[(0,0,0,'s'),(0,1,0,'s'),(1,0,0,'s'),(1,1,0,'s'),(0,0,1,'d'),(0,1,1,'d'),(1,0,1,'d'),(1,1,1,'d'),(1,2,1,'d'),(2,0,1,'d'),(2,1,1,'d'),(0,0,2,'g'),(0,1,2,'g'),(1,0,2,'g'),(1,1,2,'g')]
this simple list conversion is scrambling my brain. o.0
EDIT: more info:
in the input list, the last nested list represents the base layer.
The idea was to convert string i have written in a file into coordinate points. This is the content of the file:
[LVL02]
g,g
g,g
[/LVL02]
[LVL01]
d,d
d,d,d
d,d
[/LVL01]
[LVL00]
s,s
s,s
[/LVL00]
this should give me a very basic map maker. each level is a flat 2d surface.
[LVL02]
g,g (0,0,2,'g'),(0,1,2,'g')
g,g (1,0,2,'g'),(1,1,2,'g')
[/LVL02]
[LVL01]
d,d (0,0,1,'d'),(0,1,1,'d')
d,d,d (1,0,1,'d'),(1,1,1,'d'),(1,2,1,'d')
d,d (2,0,1,'d'),(2,1,1,'d')
[/LVL01]
[LVL00]
s,s (0,0,0,'s'), 0,1,0,'s')
s,s (1,0,0,'s'),(1,1,0,'s')
[/LVL00]
ie. (xaxis,yaxis,zaxis, type)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它可能是这样的:
...但是正如它所写的那样,尚不清楚规则到底是什么。在嵌套循环中:
It might be this:
... but as it has been written, it is not clear what the rule is exactly. In nested loops: