本文介绍了如何更改以从列表中选择大于2的唯一数字计数 - 刚才,只选择了两个数字。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<pre>import random

longList = [ 0, 3, 4, 5, 6, 7, 8, 12, 15, 16, 17 ]

# Pick 2 unique numbers from longList, at random - any 2 numbers as long
# as they're not the same

uniques = [ longList[ random.randint( 0, len( longList ) - 1 ) ] ]

while len( uniques ) < 2:
    nextCandidate = random.randint( 0, len( longList ) - 1 )
    if longList[ nextCandidate ] != uniques[ 0 ]:
        uniques = uniques + [ longList[ nextCandidate ] ]

print(longList)
print("The unique numbers are", uniques[ 0 ], "and", uniques[ 1 ])





我是什么尝试过:



我输了这个我尝试了一些但不起作用



What I have tried:

I lost with this I have tried something but non works

推荐答案


这篇关于如何更改以从列表中选择大于2的唯一数字计数 - 刚才,只选择了两个数字。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 19:15