Home > Mobile >  How can code be built for a diagram with array elements looped?
How can code be built for a diagram with array elements looped?

Time:07-06

enter image description here

In the image below, I came up with something like this but I know this produces an error. I am writing in python

    def return_this(arr,x,y):
        arr = [10, [30, [x,y], 40]]
        return arr[1][0]

CodePudding user response:

here is your solution, you need to create 4 array with values and for empty one put None at start.

Now once declare you need to reference the array to other array. and it is done you can check them out but indexing the internal indexes where they point out


>>> 
>>> a =[None, None]
>>> b =[10, None]
>>> c = [None, 20]
>>> d = [30, None, 40]
>>> 
>>> a[0] = b
>>> a[1] =c
>>> b[1] = d
>>> c[0] =d
>>> d[1] = a
>>> 
>>> a
[[10, [30, [...], 40]], [[30, [...], 40], 20]]
>>> b
[10, [30, [[...], [[...], 20]], 40]]
>>> c
[[30, [[10, [...]], [...]], 40], 20]
>>> d
[30, [[10, [...]], [[...], 20]], 40]

note: you need to return a[0] in your function

  • Related