subject

Write a function that accepts a list of lists and merges all of the items in the sublists into a single new list. The function should merge all of the elements (see example below) using only list comprehension, and return the newly created list. The original list (passed to the function) should not be modified in any way.

For example, in the code below, we create a list of lists. Each sublist may contain any type of data (and data in any sublist can be of different types).

This list of lists (some_list) is then passed to your function, which will return a new list. When printing the list that is returned by the function (printing is NOT performed in the function), you will see that the sublists have been merged into one overall list.

The order of the merge is as follows: first, all of the first sub-list's elements (in order they appeared), and then all of the second sub-list's elements, and so on.

For example, given the following code snippet,

some_list = [ [1, 2.0, True, "some string", 5], \
['NYU', False, (1, 2), {'joe':34.44, 'mary':67.55}, [1, 2, 3, 4, 5]] \
]
the sequence above would produce the following output:

[1, 2.0, True, 'some string', 5, 'NYU', False, (1, 2), {'joe': 34.44, 'mary': 67.55}, [1, 2, 3, 4, 5]]
Note carefully, that in the example above, the second sublist (that starts with the element 'NYU') has a fifth element that is a list (the list [1, 2, 3]). This fifth element is inserted into the function's resulting list without modification (it does not decompose the [1, 2, 3] list into smaller elements.

Extra Credit

For +5 points of extra credit: write the function such that the length of the sublists do not have to be the same. For example:

some_list = [ ['a','b'], [True, False, True], \
[1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9] \
]
print(merge_sub_lists(some_list)) would produce:

['a', 'b', True, False, True, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9]
Note

Only solutions that use a list comprehension will be considered for any credit. Solving this problem with any other approach will not receive any credit.

Consider testing your solution with a variety of sample cases, not just the example provided above.

You may assume that the list will not be empty, nor will any element in the list be an empty list.

Hint

The function is literally a single statement. This is true for either solution (with or without the extra credit).

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 17:40
Consider the simple 3-station assembly line illustrated below, where the 2 machines at station 1 are parallel, i.e., the product only needs to go through one of the 2 machines before proceeding to station 2.what is the throughput time of this process?
Answers: 2
question
Computers and Technology, 24.06.2019 00:00
Visualizing a game of “tag” to remember the meaning of contagious
Answers: 3
question
Computers and Technology, 24.06.2019 16:50
7.23 main lab 7 - online shopping cart background this main lab extends the earlier prep lab "online shopping cart part 1". (you should save this as a separate project from the earlier prep lab). you will create an on-line shopping cart like you might use for your on-line purchases. the goal is to become comfortable with setting up classes and using objects. requirements this lab can be done individually or as pair programming. expanded itemtopurchase class (15 points) extend the itemtopurchase class as follows. we will not do unit testing in this lab so we will not be giving you the names of the member functions. create good ones on your own. create a parameterized constructor to assign item name, item description, item price, and item quantity (default values of "none" for name and description, and 0 for price and quantity). additional public member functions set an item description get an item description print the cost of an item - outputs the item name followed by the quantity, price, and subtotal (see example) print the description of an item - outputs the item name and description (see example) additional private data members a string for the description of the item. example output of the function which prints the cost of an item: bottled water 10 @ $1.50 = $15.00 example output of the function which prints the item description:
Answers: 1
question
Computers and Technology, 25.06.2019 01:00
Why is outfitting a workplace with video games in a technology development company consiered a strategic use of money
Answers: 1
You know the right answer?
Write a function that accepts a list of lists and merges all of the items in the sublists into a sin...
Questions
question
Chemistry, 30.08.2021 01:00
question
Mathematics, 30.08.2021 01:00