我试图从python中的列表元素生成列表。
例如:有一个包含以下信息的列表:
list=['AB4', 'AB3','AC3', 'BC4', 'BC5']
这是列表元素的确切格式。
我支持为每个元素创建列表,分别为字母(将两个字母视为一个块)和数字创建列表,这些元素将包含字符串中缺少的字符。我的意思是:
AB:['4', '3']
AC:['3']
BC:['4', '5']
4:['AB', 'BC']
3:['AB', 'AC']
5:['BC']
这些是我应该从原始列表生成的列表。原始列表中的元素没有限制,其格式与示例“两个字母和一个数字”完全相同。你知道吗
先谢谢你。你知道吗
这个怎么样
这样就可以了:
你可以用这个来打印你想要的:
输出:
您可以使用regex(^{} 模块)和^{} 来实现这一点。以下内容适用于输入字符串的非数字/数字部分的任意长度:
相关问题 更多 >
编程相关推荐