input_tuple = ('a.fish@lancaster.ac.uk 14', 'aaronz@vt.edu 110', 'ajpoland@iupui.edu 48', 'antranig@caret.cam.ac.uk 18', 'arwhyte@umich.edu 27', 'bahollad@indiana.edu 4', 'bkirschn@umich.edu 27', 'chmaurer@iupui.edu 111',)
dict = {}
for val in input_tuple:
temp_val = val.split(' ')
dict[temp_val[0]]=int(temp_val[1])
print (dict)
输出:
{'aaronz@vt.edu': 110, 'ajpoland@iupui.edu': 48, 'bahollad@indiana.edu': 4, 'antranig@caret.cam.ac.uk': 18, 'chmaurer@iupui.edu': 111, 'arwhyte@umich.edu': 27, 'bkirschn@umich.edu“:27,”a。fish@lancaster.ac.uk': 14}
以上内容将有助于在python中从元组中提取数字和字符。
你能澄清一下“那么我想把max#和email添加到一个字符串中。”