The following may hint you at what's going on:
numList = [6,9,32,39,61,75,60,63,22,49,26,4,64,54,78,43,1,47,46,17,69,20,85,71,93,28,89,67,14,88,15,73,96,86,55,79,68,76,94,65]
def PenTune():
e = list(enumerate(numList)) # only listify it once
for _ in range(5): # or how many random index-value pairs you want
yield random.choice(e)
for pos, item in PenTune():
print("pos:", pos, "itemvalue:", item)
pos: 37 itemvalue: 76
pos: 16 itemvalue: 1
pos: 29 itemvalue: 88
pos: 32 itemvalue: 96
pos: 8 itemvalue: 22
A less wasteful implementation:
def PenTune():
for _ in range(5):
i = random.randint(0, len(numList)-1)
yield i, numList[i]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…