【问题标题】:Adding and deleting random entries from a list inside another list in Python?在 Python 中的另一个列表中添加和删除列表中的随机条目?
【发布时间】:2017-12-24 22:24:06
【问题描述】:

所以,我有一些列表,并希望将这些列表中的随机条目添加到另一个列表中。这个列表稍后应该被一些条目随机清理。

我该怎么做?

【问题讨论】:

    标签: python list random


    【解决方案1】:

    您可以使用random.choice() 并执行以下操作:

    import random
    for i in range(4): # add 4 entries from l2 and l3
        l.append(random.choice(l2))
        l.append(random.choice(l3))
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2014-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-29
      • 1970-01-01
      • 2021-02-23
      • 1970-01-01
      相关资源
      最近更新 更多