Puzzle 17 - Flatten the list and Count the Occurrences

SAS
0
Flatten a Nested List and Count Occurrences in Python

You’ve been given a jumbled guest list where names are stored in a nested structure of lists within lists. Some guests appear more than once — that’s okay. Your goal is to unpack this structure into a flat list and count the occurrence of each item and display the output. This solution should work with any level of nesting.


Input & Expected Output

Input List

Guests = ["John Doe","Jane Doe",["Emily Doe","John Doe","Michael Smith"],["sarah Johnson",["Michael Smith","David Brown","Alice Green"],"Bob White","Alice Green"]]

Try solving the question yourself! If you need help, click below to reveal the solution.





Post a Comment

0Comments

Post a Comment (0)