我试图在一些分隔符的基础上组合列表中的所有元素;当分隔符对大于1时,我将面临困难。你知道吗
假设列表如下:
['{','k0c','k1b','k2b','k3b','}','{','\\g0','\\g1','\\g2','\\g3','}']
此列表中有12项
每当它找到{和}时,我希望将这些索引中的所有元素连接成一个元素,以便:
['{ k0c, k1b, k2b, k3b }' , '{\\g0 , \\g1, \\g2, \\g3 }' ]
此列表中的2项是我想要的,分隔符中的所有元素都变成了列表中的一个元素。你知道吗
Tags:
假设您的数据没有任何退化情况,我们总是希望
'}','{'
来分隔您的组。你知道吗因此,获得所需输出的简单方法是将字符串连接在一起,在
}
上拆分,然后格式化生成的列表元素。你知道吗像这样的东西应该会起作用:
输出为
但是你可以用字符串列表做任何你喜欢的事情。你知道吗
相关问题 更多 >
编程相关推荐