I was wondering if there's a way in Python to get from a list, a random value of it and its position at the same time.
I know I can do this in two steps:
list_index = random.randrange(len(my_list))
list_value = my_list[index]
Also I want to exclude if there's a 0 value inside the list. I can't use random() 1st for getting a position because this way I need to recursively call random() until I don't get a 0.
Another posibility is to call random() to get values inside the list and exclude the 0, but with this implementation if, for example, there're two (or more) indentical values, Python outputs me the 1st position:
Example:
[3 5 6 8 5 0]
Random's output value = 5
Position = 1
But 5 value is also in position 4
How can I implement this? Is it feasible? I've been thinking and searching on the web so much, but couldn't find anything.
Really thank you in advance.
Alex