這就像我知道該怎麼做,不知道我是否正確地做。如何讓程序打印列表中出現號碼的次數?
L = [4, 10, 4, 2, 9, 5, 4 ]
n = len(L)
element =()
if element in L:
print(element)
print("number occurs in list at the following position, if element not in list")
print("this number does not occur in the list")
我如何去獲得多次出現更多的元素,以打印爲
4 occurs in L at the following positions: [0, 2, 6]
所以我不必使用列表的長度? – neonlights
值得注意的是,要顯示所有元素的這些信息,你可以遍歷'set(L)''(避免多次顯示每個項目,因爲集合不存儲重複項)。 –
@neonlights你爲什麼? –