
- 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
Python - Remove positional rows
When it is required to remove positional rows, a simple iteration and the ‘pop’ method is used.
Example
Below is a demonstration of the same
my_list = [[31, 42, 2], [1, 73, 29], [51, 3, 11], [0, 3, 51], [17, 3, 21], [1, 71, 10], [0, 81, 92]] print("The list is :") print(my_list) my_index_list = [1, 2, 5] for index in my_index_list[::-1]: my_list.pop(index) print("The output is :") print(my_list)
Output
The list is : [[31, 42, 2], [1, 73, 29], [51, 3, 11], [0, 3, 51], [17, 3, 21], [1, 71, 10], [0, 81, 92]] The output is : [[31, 42, 2], [0, 3, 51], [17, 3, 21], [0, 81, 92]]
Explanation
A nested list is defined and is displayed on the console.
Another list with integer values is defined.
This list is iterated over and reversed.
Every index is deleted using the ‘pop’ method.
This is the output which is displayed on the console.
- Related Articles
- Python – Remove rows with Numbers
- Python – Remove Rows for similar Kth column element
- Remove similar element rows in tuple Matrix in Python
- Python program to remove rows with duplicate element in Matrix
- Positional Number System
- How to use one or more same positional arguments in Python?
- MongoDB pull with positional operator?
- Write a program in Python to remove first duplicate rows in a given dataframe
- Remove new line characters from rows in MySQL?
- Using positional operator with hierarchies in MongoDB?
- Find number of Positional Elements in C++
- How to remove all rows having NA in R?
- How to remove empty rows from an R data frame?
- Remove specific fields/ rows and show other records in MySQL?
- How to remove rows that contain NAs in R matrix?

Advertisements