解析包含#作为分隔符的字符串

use*_*448 -1 python regex parsing list

示例字符串 -

"{1#2#3,4#5#6,7#8#9,10#11#12}"
Run Code Online (Sandbox Code Playgroud)

我希望这是一个2D数组/列表.喜欢 -

[
  [1, 2, 3],
  [4, 5, 6],
  [7, 8, 9],
  [10, 11, 12]
]
Run Code Online (Sandbox Code Playgroud)

在python中执行此操作的最优雅方式是什么?

我试图在','的基础上先拆分.然后我得到一个清单.对于电梯中的每个项目,我将其拆分为"#".这样我就可以完成它.但我想要一个干净利落的方式.

rit*_*t93 5

>>> s="{1#2#3,4#5#6,7#8#9,10#11#12}"
>>> list(map(lambda x:list(map(int, x.split('#'))), s.strip('{}').split(',')))
[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]
Run Code Online (Sandbox Code Playgroud)

以下是每个步骤发生的情况:

>>> s
'{1#2#3,4#5#6,7#8#9,10#11#12}'
>>> s.strip('{}')
'1#2#3,4#5#6,7#8#9,10#11#12'
>>> s.strip('{}').split(',')
['1#2#3', '4#5#6', '7#8#9', '10#11#12']
>>> list(map(lambda x:x.split('#'), s.strip('{}').split(',')))
[['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9'], ['10', '11', '12']]
Run Code Online (Sandbox Code Playgroud)