# Python - Remove positional rows

PythonServer Side ProgrammingProgramming

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### Practical Machine Learning using Python

Best Seller

91 Lectures 23.5 hours

#### Practical Data Science using Python

22 Lectures 6 hours

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.

Updated on 15-Sep-2021 12:22:58