'How to converts a 2D array into a 2D doubly linked list with loops in Python

the 2D array has been given and I need to use a for-loop to converts a 2D array into a 2D doubly linked list. how can I do that? thank you!

` import numpy as np

class Node: """ Node class

        up
         |
left - data - right
         |
       down
"""

def __init__(self, data):
    self.data = data
    self.right = None
    self.left = None
    self.up = None
    self.down = None

def constructDoublyLinkedListLoop(arr): ' Converts a 2D array into a 2D doubly linked list with loops.

input:
    arr: 2D array to turn into a 2D DLL
    
output:
    top_left_ptr: head (top left node) of the 2D DLL of the input arr.
'

return top_left_ptr`


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source