
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to randomize the items of a list in Python?
The random module in the Python standard library provides a shuffle() function that returns a sequence with its elements randomly placed.
>>> import random >>> l1=['aa',22,'ff',15,90,5.55] >>> random.shuffle(l1) >>> l1 [22, 15, 90, 5.55, 'ff', 'aa'] >>> random.shuffle(l1) >>> l1 ['aa', 'ff', 90, 22, 5.55, 15]
- Related Articles
- Shuffle or Randomize a list in Java
- How to access nested Python dictionary items via a list of keys?
- How to count the number of items in a C# list?
- How to randomize rows of a matrix in R?
- How to add items to a list in C#?
- How do you remove multiple items from a list in Python?
- Insert the string at the beginning of all items in a list in Python
- How to remove items from a list in C#?
- Python - Create nested list containing values as the count of list items
- How to Randomize Lines in a File in Linux
- How to randomize (shuffle) a JavaScript array?
- How to Add Commas Between a List of Items Dynamically in JavaScript?
- Python – Sort List items on the basis of their Digits
- How to preselect a value in a dropdown list of items in HTML forms?
- Associating a single value with all list items in Python

Advertisements