If the list is in random order, you can just take the first 50.

Otherwise, use

Copyimport random
random.sample(the_list, 50)

random.sample help text:

sample(self, population, k) method of random.Random instance
    Chooses k unique random elements from a population sequence.
    
    Returns a new list containing elements from the population while
    leaving the original population unchanged.  The resulting list is
    in selection order so that all sub-slices will also be valid random
    samples.  This allows raffle winners (the sample) to be partitioned
    into grand prize and second place winners (the subslices).
    
    Members of the population need not be hashable or unique.  If the
    population contains repeats, then each occurrence is a possible
    selection in the sample.
    
    To choose a sample in a range of integers, use xrange as an argument.
    This is especially fast and space efficient for sampling from a
    large population:   sample(xrange(10000000), 60)
Answer from John La Rooy on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί randomly-select-n-elements-from-list-in-python
Randomly Select N Elements from List in Python - GeeksforGeeks
July 15, 2025 - Unlike random.sample(), this method allows repetition, meaning the same element can be selected multiple times. In this method, we shuffle the entire list and then select the first n elements.
🌐
Stack Abuse
stackabuse.com β€Ί how-to-randomly-select-elements-from-a-list-in-python
How to Randomly Select Elements from a List in Python
September 27, 2023 - We'll save the result in a new list, and if there's not enough elements to fit a final collection, it'll simply be unfinished: import random def select_random_Ns(lst, n): random.shuffle(lst) result = [] for i in range(0, len(lst), n): result.append(lst[i:i + n]) return result lst = [1, 2, 3, ...
Discussions

python - Select 50 items from list at random - Stack Overflow
I have a function which reads a list of items from a file. How can I select only 50 items from the list randomly to write to another file? def randomizer(input, output='random.txt'): query = open( More on stackoverflow.com
🌐 stackoverflow.com
python - How can I randomly select (choose) an item from a list (get a random element)? - Stack Overflow
How do I retrieve an item at random from the following list? foo = ['a', 'b', 'c', 'd', 'e'] More on stackoverflow.com
🌐 stackoverflow.com
Is there a single command to randomly select an item from a list and then delete it?
You can random.shuffle() the list and just iterate over it. It would produce the same effect. More on reddit.com
🌐 r/learnpython
8
19
March 31, 2018
python - Pick N distinct items at random from sequence of unknown length, in only one iteration - Stack Overflow
I am trying to write an algorithm that would pick N distinct items from an sequence at random, without knowing the size of the sequence in advance, and where it is expensive to iterate over the seq... More on stackoverflow.com
🌐 stackoverflow.com
🌐
PYnative
pynative.com β€Ί home β€Ί python β€Ί random β€Ί python random choice() function to select a random item from a list and set
Python random choice() function to select a random item from a List and Set
July 22, 2023 - Use random.choice() function to randomly select an item from a list, String, Dictionary, and set. Pick a single random number from a range
🌐
Note.nkmk.me
note.nkmk.me β€Ί home β€Ί python
Random Sampling from a List in Python: random.choice, sample, choices | note.nkmk.me
May 19, 2025 - Concatenate Strings in Python: + Operator, join, etc. print(tuple(random.sample(('xxx', 'yyy', 'zzz'), 2))) # ('zzz', 'yyy') print(''.join(random.sample('abcde', 2))) # be ... Note that if the original list or tuple contains duplicate elements, ...
🌐
Better Stack
betterstack.com β€Ί community β€Ί questions β€Ί python-how-to-randomly-select-list-item
How can I randomly select an item from a list in Python? | Better Stack Community
May 14, 2025 - The item that is selected will be different each time the code is run. Note that you will need to import the random module at the beginning of your code in order to use the random.choice() function.
Top answer
1 of 16
3540

Use random.choice():

import random

foo = ['a', 'b', 'c', 'd', 'e']
print(random.choice(foo))

For cryptographically secure random choices (e.g., for generating a passphrase from a wordlist), use secrets.choice():

import secrets

foo = ['battery', 'correct', 'horse', 'staple']
print(secrets.choice(foo))

secrets is new in Python 3.6. On older versions of Python you can use the random.SystemRandom class:

import random

secure_random = random.SystemRandom()
print(secure_random.choice(foo))
2 of 16
306

If you want to randomly select more than one item from a list, or select an item from a set, I'd recommend using random.sample instead.

import random
group_of_items = {'a', 'b', 'c', 'd', 'e'}  # a sequence or set will work here.
num_to_select = 2                           # set the number to select here.
list_of_random_items = random.sample(group_of_items, num_to_select)
first_random_item = list_of_random_items[0]
second_random_item = list_of_random_items[1] 

If you're only pulling a single item from a list though, choice is less clunky, as using sample would have the syntax random.sample(some_list, 1)[0] instead of random.choice(some_list).

Unfortunately though, choice only works for a single output from sequences (such as lists or tuples). Though random.choice(tuple(some_set)) may be an option for getting a single item from a set.

EDIT: Using Secrets

As many have pointed out, if you require more secure pseudorandom samples, you should use the secrets module:

import secrets                              # imports secure module.
secure_random = secrets.SystemRandom()      # creates a secure random object.
group_of_items = {'a', 'b', 'c', 'd', 'e'}  # a sequence or set will work here.
num_to_select = 2                           # set the number to select here.
list_of_random_items = secure_random.sample(group_of_items, num_to_select)
first_random_item = list_of_random_items[0]
second_random_item = list_of_random_items[1]

EDIT: Pythonic One-Liner

If you want a more pythonic one-liner for selecting multiple items, you can use unpacking.

import random
first_random_item, second_random_item = random.sample({'a', 'b', 'c', 'd', 'e'}, 2)
Find elsewhere
🌐
Sling Academy
slingacademy.com β€Ί article β€Ί python-ways-to-select-random-elements-from-a-list
Python: 3 Ways to Select Random Elements from a List - Sling Academy
July 6, 2023 - random.choices() is a function in the random module that returns a list of k random elements from a population with replacement (i.e., the same element can be selected more than once). If k is not specified, it defaults to 1. ... import random # Set the seed to 0 so that the results are the ...
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί randomly-select-elements-from-list-without-repetition-in-python
Randomly select elements from list without repetition in Python - GeeksforGeeks
July 15, 2025 - random.shuffle() function randomly rearranges the list, and we can take the first n elements as the selection. ... import random a = [10, 20, 30, 40, 50] # Shuffling the list random.shuffle(a) # Selecting first 3 elements res = a[:3] print(res)
🌐
Reddit
reddit.com β€Ί r/learnpython β€Ί is there a single command to randomly select an item from a list and then delete it?
r/learnpython on Reddit: Is there a single command to randomly select an item from a list and then delete it?
March 31, 2018 -

Hi, I searched but didn't find anything.

Basically, I want something which combines random.choice() and list.pop() - the idea being that the command will randomly choose an item from the list, return it, and delete it.

The use case is that I have a list of items that I want to process in a random order; once they are processed they will be removed from the list so that they can't be randomly selected again. This continues until the list is empty.

I've implemented this with a combination of random.choice() and pop() as follows:

foo = ['a','b','c','d','e','f']
    while len(foo) > 0:
        random_index = random.randint(0,len(foo) - 1)
        randomly_selected_item = foo.pop(random_index)

It feels like the last two lines could be replaced with random.remove_random_item(list) if such a thing existed.

🌐
datagy
datagy.io β€Ί home β€Ί python posts β€Ί python: select random element from a list
Python: Select Random Element from a List β€’ datagy
December 19, 2022 - It also provides a seed generator ... way to use Python to select a single random element from a list in Python is to use the random.choice() function....
🌐
PythonForBeginners.com
pythonforbeginners.com β€Ί home β€Ί select random element from a list in python
Select Random Element from A List in Python - PythonForBeginners.com
February 18, 2022 - While using the numpy module, we ... If we want to select n random elements from a given list, we will pass the number n as the second input argument to the choice() function defined in the numpy module....
🌐
Newtum
blog.newtum.com β€Ί randomly-select-element-from-list-in-python-using-choices
Randomly Select Element From List in Python Using choices() - Newtum
April 24, 2024 - With a single function call, random.choices(list, k=n), we obtain a list containing n randomly chosen elements from the original list. The code highlights the simplicity and effectiveness of the random.choices() function in generating random ...
🌐
Python Pool
pythonpool.com β€Ί home β€Ί blog β€Ί 6 popular ways to randomly select from list in python
6 Popular Ways to Randomly Select from List in Python - Python Pool
August 26, 2021 - Next using random.randrange() to get a random element from the list. ... A secret is a module that is in-built in python.
🌐
Newtum
blog.newtum.com β€Ί randomly-select-element-from-list-in-python-using-sample
Randomly Select Element From List in Python Using sample() - Newtum
April 24, 2024 - In conclusion, the Python code ... a list. By importing the random module and initializing a list with multiple elements, we can specify the number of elements we want to select from the list using the variable n...
🌐
Python Engineer
python-engineer.com β€Ί posts β€Ί randomly-select-item
How to randomly select an item from a list? - Python Engineer
February 3, 2022 - This is similar to random.sample and lets you pass the number of rand items you want as a parameter. This method returns a list. Unlike random.seed, you can not use a seed to keep the random element(s) generated by the secrets library consistently.
🌐
O'Reilly
oreilly.com β€Ί library β€Ί view β€Ί python-cookbook β€Ί 0596001673 β€Ί ch02s09.html
Selecting Random Elements from a List Without Repetition - Python Cookbook [Book]
July 19, 2002 - def faster( ): while data: index = random.randrange(len(data)) elem = data[index] # direct deletion, no search needed del data[index] process(elem) # the same, but preserving the data list def faster_preserve( ): aux = range(len(data)) while aux: posit = random.randrange(len(aux)) index = aux[posit] elem = data[index] # alters the auxiliary list only del aux[posit] process(elem) However, the key improvement is to switch to an O(N) algorithm:
Authors Β  Alex MartelliDavid Ascher
Published Β  2002
Pages Β  608
🌐
Spark By {Examples}
sparkbyexamples.com β€Ί home β€Ί python β€Ί select random item from list in python
Select Random Item from List in Python - Spark By {Examples}
May 31, 2024 - # Using random.choice() import random my_list = [1, 2, 3, 4, 5] random_choice = random.choice(my_list) print("Selected:", random_choice) When I run this, I get the value 5 as a random element from the list. The random.sample() function is another ...