Random without repetition in Python

前端 未结 3 1235
遥遥无期
遥遥无期 2020-12-12 03:50

I want to write a program that displays all the elements of a list in random order without repetition. It seems to me that it should work, but only prints those elements wi

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-12 04:15

    Read about capabilities of Random library. It can write simpler. For example:

    import random
    
    data = ["house", "word", "computer", "table", "cat", "enter", "space"]
    x = random.sample(data, len(data))
    print(x)
    

提交回复
热议问题