访问 python 中的嵌套元素
Accessing nested elements in python
我是 python.I 的新手,这是我第一次在这里发帖,我知道问题可能很基础,但问题是我自己搞不懂。
假设我有
列表=[("a,"b"),("c","d"),("e","f")]
我希望用户输入其中一个元组的元素之一作为输入,另一个元素是 printed.Or 更准确地说,我会说只是 List[x][0] 中的一个元素是输入,相应的 List[x][1] 元素打印为 output.I 希望它有意义。
谢谢!
请检查 question.I 中的列表,认为您忘记了第一个元组中的引号 (")。[("a^here,"b"),("c","d"),("e","f")]
我想这可能对你有帮助。
List=[("a","b"),("c","d"),("e","f")]
c=raw_input('ENTER A CHARACTER-')
for i in xrange(len(List)):
if c in List[i]:
ind=List[i].index(c)
print List[i][abs(ind-1)]
break
我是 python.I 的新手,这是我第一次在这里发帖,我知道问题可能很基础,但问题是我自己搞不懂。
假设我有 列表=[("a,"b"),("c","d"),("e","f")]
我希望用户输入其中一个元组的元素之一作为输入,另一个元素是 printed.Or 更准确地说,我会说只是 List[x][0] 中的一个元素是输入,相应的 List[x][1] 元素打印为 output.I 希望它有意义。 谢谢!
请检查 question.I 中的列表,认为您忘记了第一个元组中的引号 (")。[("a^here,"b"),("c","d"),("e","f")] 我想这可能对你有帮助。
List=[("a","b"),("c","d"),("e","f")]
c=raw_input('ENTER A CHARACTER-')
for i in xrange(len(List)):
if c in List[i]:
ind=List[i].index(c)
print List[i][abs(ind-1)]
break