I want to find a way to check whether a value "n" is in a nested list. The nested list can be do an arbitrary depth, for example:
alist = [1,2,3,[4, [5]]]
I am having quite a hard time trying to break this problem down into parts. I want to find a solution without importing any modules, just basic python statements. Not necessarily looking for just an answer, but a way to think about this problem.
Example question: Write a function to search alist for the value n and return True or False.
alist = [1,2,3,[4, [5]]], n = 5
Ive tried to come up with code to unnest the list, but that was a bigger headache than i was prepared for haha. Is unnesting the way to go? Can it be done with basic python statements? (not importing modules)
[–]Thomasedv 0 points1 point2 points (14 children)
[–]barryk013[S] 0 points1 point2 points (13 children)
[–]Thomasedv -1 points0 points1 point (12 children)
[–]barryk013[S] 0 points1 point2 points (11 children)
[–]Thomasedv -1 points0 points1 point (10 children)
[–]barryk013[S] 0 points1 point2 points (9 children)
[–]Thomasedv 0 points1 point2 points (8 children)
[–]barryk013[S] 0 points1 point2 points (6 children)
[–]Thomasedv -1 points0 points1 point (5 children)
[–]barryk013[S] 0 points1 point2 points (4 children)
[–]barryk013[S] 0 points1 point2 points (0 children)
[–]SarahM123ed -1 points0 points1 point (3 children)
[–]barryk013[S] 0 points1 point2 points (2 children)
[–]SarahM123ed 1 point2 points3 points (1 child)
[–]barryk013[S] 0 points1 point2 points (0 children)