【发布时间】:2017-10-30 11:26:11
【问题描述】:
我有一个多行字符串,我想使用 Python 2.7 将其转换为元组字典
我的字符串是:
data = '''1 George 1789
2 John 1797
3 Thomas 1801
5 James 1817'''
让我们调用字典:
pres{}
我希望键为 1,它吐出的值为“George”和“1789”。
print pres[1]
应该给
George,1789
【问题讨论】:
-
有什么问题?
-
这个问题都没有使用有效的语法,你想要有效语法的答案吗?
-
抱歉,我是编码新手,不确定。我希望命令 print pres[5] 显示 James,1817
-
那么最好通过tutorial。先尝试一下。
标签: python string python-2.7 dictionary tuples