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,...
-
Cars A and B are d = 60 m apart and are traveling respectively at the constant speeds of (vA)0 = 32 km/h and (vB)0 = 24 km/h on an icecovered road. Knowing that 45 s after driver A applies his brakes...
-
On December 1, 2019, Robert Santo, the accountant for Euro Specialty Products, downloaded the companys November 30, 2019, bank statement from the banks website. The balance shown on the bank...
-
Discrimination against women occurs for many reasons. Why do you think it has been so persistent over time? And why might microfinance have the power to bring changes?
-
Tony and Suzie see the need for a rugged all-terrain vehicle to transport participants and supplies. They decide to purchase a used Suburban on July 1, 2022, for $12,000. They expect to use the...
-
a11 a12 a13 The matrix A = a21 a22 a23 = a31 a32 a33 [3-2 0 det 9 -1-2 2 = -9 4 -1-2 -23+( )2+( 301 9-12 -94-1 has characteristic equation )2+( )= 0. The eigenvalue with positive imaginary part is =...
-
Consider the following string of page references 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2. Complete a figure similar to Figure 8.14, showing the frame allocation for: a. FIFO (first-in-first-out) b. LRU...
-
Due to technological advancements in the use of labour and in the ability to extract deeper and smaller mineral deposits more efficiently, and the emergence of new uses for Mineral X have all...
-
How can applied ethics be used to address contemporary ethical issues such as bioethics, environmental ethics, and business ethics, and what methodologies are most effective in resolving these...
-
You are consulted by Sam and Mary Sithole in connection with their Will. They are a young married couple with two children, a son Pano of 12 years and a daughter Samantha of 8 years. Sam and Mary are...
-
What are some risks and challenges IKEA is likely to face as a result of basing its minimum pay on the living wage formula, rather than just legal requirements and the market rate? Given that IKEA's...
-
What constitutes an ethical dilemma, and how can individuals and organizations navigate such dilemmas when faced with conflicting moral imperatives ?
-
ABC, Inc. acquired a competitor from a private company on June 1 . No receivables were acquired with the purchase. Therefore, total accounts receivable on June 1 had a zero balance. ABC, Inc. plans...
-
please help. Marker Pens are ordered twice each year by MPE department, and the reorder point, without safety stock is 50 marker pens. Inventory carrying cost is BDT 5 per pen per year, and the cost...
-
Classify each of the following activities as proper or prohibited under the various consumer statutes you have studied. a. Calling a hospital room to talk to a debtor who is a patient there. b....
-
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...
-
Identify organizations in your area that fit each business market category: producer, reseller, government, and institutional. Explain your classifications.
-
Barajas Printing Corp. uses a job order cost system. The following data summa- Prepare entries for manufacrize the operations related to the first quarter's production. turing costs. (SO 2, 3, 4. 5)...
-
Purchases by businesses may be described as new-task, modified rebuy, or straight rebuy. Categorize the following purchase decisions and explain your choices. a. Bob has purchased toothpicks from...
Micromanufacturing International Research And Development 1st Edition - ISBN: 1402059485 - Free Book
Study smarter with the SolutionInn App