I'm currently trying to create a program that randomly selects two elements at a time from a list for a user to compare, WITHOUT comparing two elements twice OR the same element for myself .
list1 = ['item1', 'item2', 'item3', 'item4', 'item5']
In list1 , I would like to use random.choice:
item_chosen = random.choice(list1) print(item_chosen) item_chosen2 = random.choice(list1) print(item_chosen2)
The problem here is that item_chose can be the same as item_chosen2 , and that if I set the loop, then the same comparisons will be performed more than once. In addition, the program must understand when all elements of the list are compared with each other (too much time would be required for manual comparison between all elements in each combination).
source share