def findElement(elm=1, tup1=(1,2,3,4,1)):
"""
Return the indexes where the element is present
"""
# We initiate the variable that will contain the list of index
result = []
# i will give us here the index of currently read element (tup1)
for i in range(len(tup1)):
if tup1[i] == elm:
result.append(i)
return result
我将使用
for i in range(len(tup1)):
来获取当前读取元素的索引以下是一些方法,按我的喜好排列。第二个使用generator
列表理解:
发电机功能方法:
不带生成器的函数方法:
相关问题 更多 >
编程相关推荐