samedi 2 mai 2020

How to get an unsorted range in Python

I have a list here

List = ['first', 'second', 'third', 'fourth', 'etc']

now I want to iterate through the list List randomly with random indices and print each item in the specific index. For example I want the output to look something like this:

Output:

fourth
first
etc
third
second

When I use for loop with range() then it'll only iterate through the list in the order of indices that starts from 0 and ends at the stop. What I want is when I iterate through the list I want each index to be random but without repeating. Is this possible? I suppose so (¬‿¬).

If there is any way I can do it. Please answer this it'll be really helpful.

Thank You




Aucun commentaire:

Enregistrer un commentaire