{"id":17203,"date":"2021-08-26T10:42:53","date_gmt":"2021-08-26T05:12:53","guid":{"rendered":"https:\/\/python-programs.com\/?p=17203"},"modified":"2021-11-22T18:37:10","modified_gmt":"2021-11-22T13:07:10","slug":"python-program-to-delete-random-item-from-a-list","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-delete-random-item-from-a-list\/","title":{"rendered":"Python Program to Delete Random Item from a List"},"content":{"rendered":"

In the previous article, we have discussed Python Program to Print Items from a List with Specific Length<\/a>
\nRandom Module in python :<\/strong><\/p>\n

As this Random module is one of Python’s predefined modules, its methods return random values.<\/p>\n

It selects integers uniformly from a range. For sequences, it has a function to generate a random permutation of a list in-place, as well as a function to generate a random sampling without replacement. Let’s take a look at how to import the Random Module.<\/p>\n

The random module in Python is made up of various built-in Methods.<\/p>\n

The random module is extremely useful for creating a variety of entertaining games.<\/p>\n

choice():<\/strong>\u00a0 choice() is used to select an item at random from a list, tuple, or other collection.<\/p>\n

Because the choice() method returns a single element, we will be using it in looping statements.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given List = ['apple', 'mango', 'banana', 'orange']<\/pre>\n

Output:<\/strong><\/p>\n

The given list after deletion of random item = ['apple', 'banana', 'orange']<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given List = ['good', 'morning', 'btechgeeks', 'hello', 'all']<\/pre>\n

Output:<\/strong><\/p>\n

The given list after deletion of random item = ['good', 'morning', 'hello', 'all']<\/pre>\n

Program to Delete Random Item from a List<\/h2>\n

Below are the ways to Delete Random items from a given List.<\/p>\n