I have a list of integers: l = [1,2,3,4]
For each element in this list I need to randomly select a different element and perform some operation on it:
for i in range(len(l)):
idx = # a random index which is NOT equal to i
# do something with the element at idx
I'm still pretty new to Python and can't determine if there is a way to do this without resorting to a loop where I generate a random index and only stop the loop if the random number is not equal to i
. Any suggestions would be greatly appreciated.