fork download
  1. import random
  2.  
  3. lst_sam = ["a", "b", "c"] # 确保正确初始化
  4. mod_set = ["a", "b", "c"]
  5. total_ct = 0
  6. lst = lst_sam # 修正为使用copy方法创建lst的副本
  7.  
  8. for i in range(0, 100000):
  9. # initialize pool
  10. fin_set = set()
  11. ct = 0
  12.  
  13. # loop when sets do not match
  14. while fin_set != mod_set:
  15. if not lst: # 检查lst是否为空
  16. break # 如果为空,则跳出循环,可以根据实际情况决定如何处理
  17. tmp = random.choice(lst) # 从lst中随机选择元素
  18. if tmp not in fin_set: # 确保不会添加重复元素
  19. fin_set.add(tmp)
  20. lst.remove(tmp)
  21. ct += 1
  22. total_ct += ct
  23.  
  24. print(total_ct / 100000)# your code goes here
Success #stdin #stdout 0.07s 12892KB
stdin
Standard input is empty
stdout
0