[('12121212', 'computer', 'computer@123'), ('1223', 'asus', 'asus@123'), ('1111', 'testpro', 'testpro@123')]
如果我要在python中输入元组中存在的其他两个值,我想从列表中的元组中获取一个值。假设fvalue = computer和svalue = 12121212那么我将获得tvalue作为计算机@ 123
如果我理解你想要的东西,这样的东西。这将搜索具有您的2个值的元组并返回第三个。
a = [('12121212', 'computer', 'computer@123'), ('1223', 'asus', 'asus@123'), ('1111', 'testpro', 'testpro@123')]
value1 = '1111'
value2 = 'testpro@123'
def search(val1, val2, list_to_search):
for item in list_to_search:
if val1 in item and val2 in item:
item = list(item)
item.remove(val1)
item.remove(val2)
return item[0]
return None
print(search(value1, value2, a))
结果:testpro