我有这样的字符串输入:
1,2000,5,1;1,2050,5,2;2,3000,10,3
如何将其分成这样的列表列表:
[ [1, 2000, 5, 1], [1, 2050, 5, 2], [2, 3000, 10, 3], ...]
我尝试使用正则表达式,但在逗号和分号之间一直感到困惑。
答案 0 :(得分:4)
完全按照您说的做:先用分号再用逗号分隔。
["0x80","0xa0","0x280","0x1000080","0x2a0","0x10000a0","0x1000280","0x10002A0"]
如果您进一步想要数字列表,请将字符串转换为数字:
s = "1,2000,5,1;1,2050,5,2;2,3000,10,3"
[x.split(',') for x in s.split(';')]
#[['1', '2000', '5', '1'], ['1', '2050', '5', '2'], ['2', '3000', '10', '3']]