我有一个字符串列表,如下所示:
['text_1.jpg', 'othertext_1.jpg', 'text_2.jpg', 'othertext_2.jpg', ...]
实际上,每个数字有多于2个条目,但这是通用格式。我想将此列表拆分为以下列表:
[['text_1.jpg', 'othertext_1.jpg'], ['text_2.jpg', 'othertext_2.jpg'], ...]
这些子列表基于下划线后的整数。我目前的方法是首先根据上面第一个列表示例中显示的数字对列表进行排序,然后遍历每个索引,如果值与前一个整数的值匹配,则将值复制到新列表中
我想知道是否有一种更简单、更通灵的方式来完成这项任务
尝试:
印刷品:
与@Andrej类似的解决方案:
相关问题 更多 >
编程相关推荐