所以說我有list1和list2。如何使列表中的一個元素使用python調用另一個列表中的元素?
list1 = [n1,n2,n3,n4,n5,n6,n7,n8,n9,n0,star,pound]
list2 = [1,2,3,4,5,6,7,8,9,0,star,pound]
如何寫一個函數,當列表中的一個元素被調用時,list2中的相應元素被調用?
這可能已在另一篇文章中得到解答,但我一直無法找到和/或理解如何做到這一點。
---編輯---
約翰·科爾曼的評論回答我的問題,而是要幫助別人,將來讀這我會澄清一些事情。
「呼叫」可能是錯誤的用語,我絕對是編程的新手。這裏是我在這個線程的幫助下如何使用代碼。
n1 = 5
n2 = 6
n3 = 13
n4 = 19
n5 = 26
n6 = 12
n7 = 16
n8 = 20
n9 = 12
n0 = 4
star = 17
pound = 27
inputs = [n1,n2,n3,n4,n5,n6,n7,n8,n9,n0,star,pound]
numbers = [1,2,3,4,5,6,7,8,9,0,star,pound]
shows = dict(zip(inputs,numbers))
count = 1
def loop2():
for input in inputs:
if GPIO.input(input) == False:
print '%s' % shows[input]
「調用」列表元素意味着什麼?您的列表似乎不包含可馴化的東西。 –
你能澄清你所說的「列表中的元素被稱爲」的意思嗎?通常作爲可以調用的東西的功能。這是一個函數名稱列表嗎? – JawguyChooser