Hi, I need to create a function using recursion to find out if two lists have the same shape. For example, if nest1 = [4, [ [3,6], [] ,7] , ]
nest2 = [ [  ] , 7 , [ [5 , [9 , 2] , [ [ [ [  ] , 2 ] ] ] ] ] ]
nest3 = [ 5, [ [3,9], [] ,7] ,

then

isomorphic ( nest1 , nest2 ) should yield False
isomorphic ( nest1 , nest3 ) should yield True
isomorphic ( nest2 , nest3 ) should yield False

How would you set this up?

Thanks!

## Recommended Answers

Compute `isomorphic(nestA, nestB)` by hand without a computer and note carefully every single step of your reasonning. This will give you pseudo code. Then write the pseudo code, then implement.

## All 3 Replies

Compute `isomorphic(nestA, nestB)` by hand without a computer and note carefully every single step of your reasonning. This will give you pseudo code. Then write the pseudo code, then implement.

My implementation is cute two two branch ifs and this is the trace of running the function with trace decorator two of you examples as input.

``````|   isomorphic ([4, [[3, 6], [], 7], ], [[], 7, [[5, [9, 2], [[[[], 2]]]]]])
|      isomorphic (4, []) = False
|       = False
|    False

|   isomorphic ([4, [[3, 6], [], 7], ], [5, [[3, 9], [], 7], ])
|      isomorphic (4, 5) = True
|
|      isomorphic ([[[3, 6], [], 7], ], [[[3, 9], [], 7], ])
|         isomorphic ([[3, 6], [], 7], [[3, 9], [], 7])
|            isomorphic ([3, 6], [3, 9])
|               isomorphic (3, 3) = True
|
|               isomorphic (, )
|                  isomorphic (6, 9) = True
|
|                  isomorphic ([], []) = True
|                   = True
|                = True
|
|            isomorphic ([[], 7], [[], 7]) = True
|             = True
|
|         isomorphic ([], [])
|            isomorphic (, )
|               isomorphic (8, 2) = True
|
|               isomorphic ([], []) = True
|                = True
|
|            isomorphic ([], []) = True
|             = True
|          = True
|       = True
|    True
``````

thanks, I think I finally got it!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.