Flattening a List
Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.
Write a program that does a top-level "flatten" of a list. That is, given a list whose elements are all sequences themselves (strings, lists, or tuples), print a list which contains all the elements of those sequences, in the same order.
The first line of your program should set up a variable l
to hold the input list. For example:
l = [(1, 2, 3), ["a", "b", "c"], [0], "hi", ["more", "examples"]]
Your program should print the flattened result:
[1, 2, 3, "a", "b", "c", 0, "h", "i", "more", "examples"]
Notice that the elements of the input list's elements are not flattened: "more"
does not become "m", "o", "r", ...
.1
Once you've tested your code by hand, upload your file for testing:
No file selected