How to reverse two dimensional array in python

In this tutorial, we will learn how to reverse the two-dimensional array in python with some cool and easy examples. In many situations, you might have to come up with this type of requirements and your confused in that situation. don’t be so confused, we have come up with the cool and tricky code.

We hope you will get help from this easy tutorial.

Reverse two dimensional array in python

Here we are using two different tricky methods that how to reverse a two-dimensional array in python.

first method:

Here in python, the reverse function can convert any array into reverse order, Thus we can easily use the built-in function without taking extra effort to make this essential conversion.




The type of reverse function is called NoneType

Example:

name=[[value],[value1],[value2]]

name.reverse function

print(name)

in this above example if the value is string the must have to put value in between this ” value”, if it is a string then u should give value directly

in above reverse function,n, it can reverse the array, it is built-in-function without taking extra effort to make this essential reverse conversion.

arr=[["3v"],["kanchana"],["siresha"],["ramya"]] 
arr.reverse()
print("your reverse 2D array is :"arr)

Output:

your reverse 2D array is : [[‘ramya’], [‘siresha’], [‘kanchana’], [‘3v’]]

 

Second method:

Here we can use index values to reverse the two-dimensional array, by locating the array in the list it can show line wise while we locate index wise, but the can change and locate the array in descending order then it will print reverse order.

The above example reverses two-dimensional array can reverse every time and does not repeated because it is not fixed.

Example:

name=[[value],[value1],[value2]]

print(name[::-1])

The above example reverse two-dimensional repeated because it is fixed.

arr=[[1,2],[3,4],[5,6]] 
print(arr[::-1])

Output:

[[5, 6], [3, 4], [1, 2]]

Also read:


One response to “How to reverse two dimensional array in python”

  1. tech sis says:

    Super sir!!!!! thank you……

Leave a Reply

Your email address will not be published. Required fields are marked *