Some examples of possible inputs and corresponding return values: flatten ([[1,2,3], [4,5,6], [7,8,9] 1) should evaluate...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Some examples of possible inputs and corresponding return values: flatten ([[1,2,3], [4,5,6], [7,8,9] 1) should evaluate to 11. 2. B 4, 5, 6, 7, 8, 9] flatten ([[1,2,3], [4, 5], [6], [], [100,101] 1) should evaluate to [1, 2, 3, 4, 5, 6, 100, 101] flatten ([]) should evaluate to [] flatten ([[1, 'a'], ['hi', [100, 200]], [2.8,['one :1),None], [[1.-5] should evaluate to [1, 'a', 'hi, [100, 200], 2.0, ('one':1), None, [], -5] (i.e., you do not need to know, or care, what the types of the nested elements are.. do not over-complicate). ● Write a function flatten() which takes a list of lists ns as an argument and returns a new list, which contains all the nested elements directly (see examples). The input argument(s) should not be modified in any way. . ● Just to make this absolutely clear, the "flattening" is "single-level" only (as also illustrated by the last example). I.e., if one of the nested elements is a list (e.g., [100,200] or [] in the above example), that doesn't matter (it stays a list-or whatever it was). Implementing a "flatten all the way down" operation would require recursion, which is beyond the scope of this class. Hint: Note that, for instance, in the second example above, the result [1, 2, 3, 4, 5, 6, 100, 101] is simply [1,2,3] + [4, 5] + [6] + []+[100, 101]. That should tell you what kind of accumulation this is (it should be a very familiar one, even syntactically)... Some examples of possible inputs and corresponding return values: flatten ([[1,2,3], [4,5,6], [7,8,9] 1) should evaluate to 11. 2. B 4, 5, 6, 7, 8, 9] flatten ([[1,2,3], [4, 5], [6], [], [100,101] 1) should evaluate to [1, 2, 3, 4, 5, 6, 100, 101] flatten ([]) should evaluate to [] flatten ([[1, 'a'], ['hi', [100, 200]], [2.8,['one :1),None], [[1.-5] should evaluate to [1, 'a', 'hi, [100, 200], 2.0, ('one':1), None, [], -5] (i.e., you do not need to know, or care, what the types of the nested elements are.. do not over-complicate). ● Write a function flatten() which takes a list of lists ns as an argument and returns a new list, which contains all the nested elements directly (see examples). The input argument(s) should not be modified in any way. . ● Just to make this absolutely clear, the "flattening" is "single-level" only (as also illustrated by the last example). I.e., if one of the nested elements is a list (e.g., [100,200] or [] in the above example), that doesn't matter (it stays a list-or whatever it was). Implementing a "flatten all the way down" operation would require recursion, which is beyond the scope of this class. Hint: Note that, for instance, in the second example above, the result [1, 2, 3, 4, 5, 6, 100, 101] is simply [1,2,3] + [4, 5] + [6] + []+[100, 101]. That should tell you what kind of accumulation this is (it should be a very familiar one, even syntactically)...
Expert Answer:
Answer rating: 100% (QA)
Python program to create and test the function flatten which takes a list of lists and retur... View the full answer
Related Book For
Probability & Statistics For Engineers & Scientists
ISBN: 9780130415295
7th Edition
Authors: Ronald E. Walpole, Raymond H. Myers, Sharon L. Myers, Keying
Posted Date:
Students also viewed these programming questions
-
A 1 defects size B D E 88888888888888888888888888 2 21 3 24 4 16 5 12 6 15 7 5 8 28 9 20 10 31 11 25 12 20 13 24 14 16 15 19 16 10 17 17 18 13 19 22 20 18 21 39 22 30 23 24 24 16 25 19 26 17 27 15...
-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 A B Total assets Sales Debt-equity ratio Return on equity D $ $ Net income 2,604 5,783 0.75 E 11% F Y3K, Inc., has sales of $5,783, total assets of...
-
1 2 3 4 5 6 7 8 9 10 Call price 11 A B Raider stock price 12 at option expiration, ST 13 14 15 16 17 18 19 20 21 22 23 0 10 20 30 40 50 60 70 80 90 100 C What is their combined profit at any S, and...
-
Bhushan Building Supplies entered into the following transactions. Prepare journal entries under the perpetual inventory system. June 1 Purchased merchandise on account from Brij Builders Materials,...
-
Which of the above multiples analyses do you believe is more appropriate ? Use the following information concerning Johnson Machine Tool Company. Johnsons income statement from the fiscal year that...
-
For the following exercises, use the matrices below to perform the indicated operation if possible. If not possible, explain why the operation cannot be performed. BC A = -10 20 201 B = [_ 5 25 40 10...
-
The beam is supported by a pin at B and a short link AC. Determine the average shear stress developed in the pins at A, B, and C. All pins are in double shear as shown, and each has a diameter of 30...
-
Pet acquired 80 percent of the common stock of Sul for $4,000,000 on January 2, 2011, when the stockholders' equity of Sul consisted of 5,000,000 euros capital stock and 2,000,000 euros retained...
-
Journalize the entry for the purchase of office supplies on February 13 for $2,300, paying $255 cash and the remainder on account. If an amount box does not require an entry, leave it blank. Feb. 13
-
Mike Curtains, a Registered Tax Agent, attends to the tax affairs of Frodo West. In preparing Frodo's 2021/22 income tax return, the following occurred: Frodo attended a meeting with Mike in August...
-
Taxpayer Ltd carries on a publishing business and owns a magazine that it publishes monthly. This company incurred the following expenditure during the year ended 30 June 2023: In a recent magazine...
-
How does lean production impact product quality and customer satisfaction?
-
How does lean production contribute to the reduction of lead time in the order fulfillment process?
-
How does lean production impact the overall employee morale and job satisfaction within an organization?
-
Consider a 345-kV transmission line with the series inductance per-unit length of wL = 0.4560/km and shunt capacitance per-unit length of wC = 4.123uU/km. [20 points] a) Calculate the surge impedance...
-
How does lean production enable organizations to better respond to disruptions and changes in the marketplace?
-
Complete a truth table for the following pair of statements and answer the question that follows. Given Truth Values A B T T T F +--- F Statement 1: Av (BC) Statement 2: F F F F T T F F FTF TFT F...
-
A superior criticized a sales manager for selling high-revenue, low-profit items instead of lower-revenue but higher-profit items. The sales manager responded, My income is based on commissions that...
-
Suppose that X and Y are independent random variables having the joint probability distribution Find (a) E (2X ? 3Y); (b) E (XY). fix,v) 4 0.10 0.15 0.20 0.30 0.10 0.15
-
Let X1 and X2 be discrete random variables with joint probability distribution find the probability distribution of the random variable Y = X1X2. 1,2,3, T1 = 1,2; 12 = f(21,22) 10, 16 elsewhere.
-
(a) What maximum light wavelength will excite an electron in the valence band of diamond to the conduction band? The energy gap is 5.50 eV. (b) In what part of the electromagnetic spectrum does this...
-
The NCAA is described as a cartel. In what way is it a cartel? What is the product being produced? How does the cartel stay together?
-
What is the cost to a firm in an oligopoly that fails to take rivals actions into account?
-
The cement industry is an example of an undifferentiated oligopoly. The automobile industry is a differentiated oligopoly. Which of these two is more likely to advertise? Why?
Study smarter with the SolutionInn App