在字典中,如何将字符串转换为列表? 让在字典中,如何将字符串转换为列表?
x = ['P: 7678643 F: 123456 E: [email protected]']
需要转换为:
y = ['P: 7678643', 'F: 123456', 'E: [email protected]']
在字典中,如何将字符串转换为列表? 让在字典中,如何将字符串转换为列表?
x = ['P: 7678643 F: 123456 E: [email protected]']
需要转换为:
y = ['P: 7678643', 'F: 123456', 'E: [email protected]']
尽管这个问题是完全错误的,这里的一些解决方案:
import re
x = ['P: 7678643 F: 123456 E: [email protected]']
Split = re.split(' ', x[0])
y = []
for i in range(0, len(Split), 2):
y.append(Split[i] + Split[i+1])
。在你的代码示例中没有字典。根据你的代码,我会使用正面表达式和负面后视。
x = ['P: 7678643 F: 123456 E: [email protected]']
y = re.split('(?<!:)\s', x[0])
import re
x = ['P: 7678643 F: 123456 E: [email protected]']
result = re.findall(r'\w+:\s\w+',x[0])
有看不到的字典。 – 2012-03-27 09:52:16