【发布时间】:2014-01-13 14:45:46
【问题描述】:
对于以下代码:
print("Welcome to the Atomic Weight Calculator.")
compound = input("Enter compund: ")
compound = H5NO3
lCompound = list(compound)
我想从列表lCompund 创建两个列表。我想要一个字符列表和另一个数字列表。所以我可能会有这样的东西:
n = ['5' , '3']
c = ['H' , 'N' , 'O']
有人可以提供一个简单的解决方案吗?
【问题讨论】:
-
您是否知道这些列表不区分 H5NO3 和 HN5O3(比如说)?您可能希望为氮存储 1(即 N = ['5','1','3'])以获得唯一的映射。
标签: python list split alpha numeric