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 06:00
Write a function that draws a pool ball. this function should take as parameters, the color, the number that should go on the pool ball, and the location of the center of the pool ball. the radius of the pool balls should be pool_ball_radius, and the font of the number should be pool_ball_font. the text of the pool ball font should be white. drawpoolball(color.orange, 5, 100, 100); drawpoolball(color.green, 6, 50, 200); drawpoolball(color.red, 3, 150, 350); drawpoolball(color.blue, 2, 250, 140); to center the numbers on the pool ball, you should use the getwidth() and getheight() methods. you are allowed to call these methods on your text object, such as txt.
Answers: 3
question
Computers and Technology, 22.06.2019 12:40
How do i get the most points, without any effort?
Answers: 2
question
Computers and Technology, 22.06.2019 23:30
What are some ways to use a range name in a formula? check all that apply. in the defined names group, click use in formula, and then select the desired name. begin typing the name in the formula, select a name from the autocomplete list, and use the arrow keys and tab key to enter the name in the formula. begin typing the formula, and then click and drag with the mouse to select the cells to include in the formula. right-click one of the cells in the range. click formula options, and use the dialog box to add the name.
Answers: 1
question
Computers and Technology, 23.06.2019 06:30
How do you write an argumentative essay about the importance of free enterprise ?
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
Mathematics, 03.02.2022 23:20
Questions on the website: 13722367