这是给定的要分割的字符串:
Succinate({3: 1, 2: 1, 4: 1, 1: 1}) initial_feed_Glutamate_C32145_Glutexc_aKG_C34251_0.5*(CS)
我想要什么:
Eg: [Succinate], [{3: 1, 2: 1, 4: 1, 1: 1}], [initial_feed_Glutamate_C32145_Glutexc_aKG_C34251_0.5*(CS)] should be outcome.
上面的输出之后,对其执行以下操作:
有人可以帮我吗?
答案 0 :(得分:0)
我认为regex会派上用场(python3版本)
from ast import literal_eval
import re
def main():
'''The Main'''
data = 'Succinate({3: 1, 2: 1, 4: 1, 1: 1}) initial_feed_Glutamate_C32145_Glutexc_aKG_C34251_0.5*(CS)'
res = list(re.match(r'^(.*)\(({.*})\)(.*)', data).groups())
dic = literal_eval(res[1])
print(dic)
print(dic[3])
if __name__ == '__main__':
main()
输出
{3: 1, 2: 1, 4: 1, 1: 1}
1