Random element in list
Returns a random element from a list.
- Use
random.choice()
to get a random element fromlst
.
from random import choice def sample(lst): return choice(lst) sample([3, 7, 9, 11]) # 9
Returns a random element from a list.
random.choice()
to get a random element from lst
.from random import choice def sample(lst): return choice(lst) sample([3, 7, 9, 11]) # 9
Executes the provided function once for each list element, starting from the list's last element.
Returns every nth
element in a list.
Returns the unique elements in a given list.
Checks if the elements of the first list are contained in the second one regardless of order.