refer to code:
...
def get_shape(l):
if isinstance(l, list):
return [len(l)] + get_shape(l[0])
else:
return []
l = [[1, 2, 3], [4, 5], [6, 7, 8, 9]]
print(get_shape(l)) # Output: [3, 3]
l = [[1, [2, 3]], [4, [5, [6, [7]]]]]
print(get_shape(l)) # Output: [2, 2, 2, 1]
...
Thank you.
๐๐ป♂️
www.marearts.com
No comments:
Post a Comment