Python programming

Create a list with values from an other list

Assuming that i have the following list

fruits=['mango','apple','orange','peach'] 

and from this list I want to create a new list randomly selecting specific number of values

then this is how it is being done for two random values of the fruits list

import random
random_fruits = random.choices(fruits, k=2)

which results to

fruits=['mango','peach'] 

Leave a Reply