SlideShare a Scribd company logo
1 of 1
PYTHON: Write a function findMaxDiff() that takes a two-dimensional list of positive integers
as a parameter. It prints the index of the row with the maximum difference between elements as
well as the value of the maximum difference in that row. The maximum difference between
elements in a row is defined to be the difference between the largest and smallest elements in the
row. The function must not modify the list passed as a parameter. You may assume that each
sublist in the parameter has at least one item in it. If there are multiple sublists that all achieve
the maximum difference, the first sublist should be reported as the one with the maximum
difference. T
Solution
def findMaxDiff(lst):
"Input:list(int); Output: (int, int)"
answer = []
index = max(range(len(lst)), key=lambda i: sum(lst[i]))
holder = enumerate(max(x) - min(x) for x in lst)
return max(x[::-1] for x in holder)
return index

More Related Content

Similar to PYTHON- Write a function findMaxDiff() that takes a two-dimensional li.docx

9781439035665 ppt ch09
9781439035665 ppt ch099781439035665 ppt ch09
9781439035665 ppt ch09
Terry Yoast
 
Need to be done in C Please Sorted number list implementation with.pdf
Need to be done in C  Please   Sorted number list implementation with.pdfNeed to be done in C  Please   Sorted number list implementation with.pdf
Need to be done in C Please Sorted number list implementation with.pdf
aathmaproducts
 
2. numanalysis.py ( 30 points) A) Write a program that asks user to e.pdf
 2. numanalysis.py ( 30 points) A) Write a program that asks user to e.pdf 2. numanalysis.py ( 30 points) A) Write a program that asks user to e.pdf
2. numanalysis.py ( 30 points) A) Write a program that asks user to e.pdf
allwayscollection
 
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfNeed done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
info114
 
numanalysis.py (30 points)A) Write a program that asks user to.pdf
numanalysis.py (30 points)A) Write a program that asks user to.pdfnumanalysis.py (30 points)A) Write a program that asks user to.pdf
numanalysis.py (30 points)A) Write a program that asks user to.pdf
amzonknr
 

Similar to PYTHON- Write a function findMaxDiff() that takes a two-dimensional li.docx (20)

1.Array and linklst definition
1.Array and linklst definition1.Array and linklst definition
1.Array and linklst definition
 
Chapter 15 Lists
Chapter 15 ListsChapter 15 Lists
Chapter 15 Lists
 
9781439035665 ppt ch09
9781439035665 ppt ch099781439035665 ppt ch09
9781439035665 ppt ch09
 
Need to be done in C Please Sorted number list implementation with.pdf
Need to be done in C  Please   Sorted number list implementation with.pdfNeed to be done in C  Please   Sorted number list implementation with.pdf
Need to be done in C Please Sorted number list implementation with.pdf
 
Write a function called countElements that counts the number of times.pdf
Write a function called countElements that counts the number of times.pdfWrite a function called countElements that counts the number of times.pdf
Write a function called countElements that counts the number of times.pdf
 
GE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_NotesGE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_Notes
 
Module-2.pptx
Module-2.pptxModule-2.pptx
Module-2.pptx
 
Data Structures Design Notes.pdf
Data Structures Design Notes.pdfData Structures Design Notes.pdf
Data Structures Design Notes.pdf
 
2. numanalysis.py ( 30 points) A) Write a program that asks user to e.pdf
 2. numanalysis.py ( 30 points) A) Write a program that asks user to e.pdf 2. numanalysis.py ( 30 points) A) Write a program that asks user to e.pdf
2. numanalysis.py ( 30 points) A) Write a program that asks user to e.pdf
 
Data structure using c module 1
Data structure using c module 1Data structure using c module 1
Data structure using c module 1
 
Python - Data Collection
Python - Data CollectionPython - Data Collection
Python - Data Collection
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
 
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfNeed done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
 
numanalysis.py (30 points)A) Write a program that asks user to.pdf
numanalysis.py (30 points)A) Write a program that asks user to.pdfnumanalysis.py (30 points)A) Write a program that asks user to.pdf
numanalysis.py (30 points)A) Write a program that asks user to.pdf
 
Python Data Types.pdf
Python Data Types.pdfPython Data Types.pdf
Python Data Types.pdf
 
Python Data Types (1).pdf
Python Data Types (1).pdfPython Data Types (1).pdf
Python Data Types (1).pdf
 
Day2
Day2Day2
Day2
 
On fuctional programming, high order functions, ML
On fuctional programming, high order functions, MLOn fuctional programming, high order functions, ML
On fuctional programming, high order functions, ML
 
Python programming : List and tuples
Python programming : List and tuplesPython programming : List and tuples
Python programming : List and tuples
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 

More from glenng10

More from glenng10 (20)

3- The affinity of major cations for soil surfaces typically follows t.docx
3- The affinity of major cations for soil surfaces typically follows t.docx3- The affinity of major cations for soil surfaces typically follows t.docx
3- The affinity of major cations for soil surfaces typically follows t.docx
 
3- Review solublity rules and identify each of the following compounds.docx
3- Review solublity rules and identify each of the following compounds.docx3- Review solublity rules and identify each of the following compounds.docx
3- Review solublity rules and identify each of the following compounds.docx
 
3- Is the boiling point of a chemical a physical property or chemical.docx
3- Is the boiling point of a chemical a physical property or chemical.docx3- Is the boiling point of a chemical a physical property or chemical.docx
3- Is the boiling point of a chemical a physical property or chemical.docx
 
3- How does a via allow a designer to route traces across one another.docx
3- How does a via allow a designer to route traces across one another.docx3- How does a via allow a designer to route traces across one another.docx
3- How does a via allow a designer to route traces across one another.docx
 
3- Assume that the DS register contains 0100 and register SI contains.docx
3- Assume that the DS register contains 0100 and register SI contains.docx3- Assume that the DS register contains 0100 and register SI contains.docx
3- Assume that the DS register contains 0100 and register SI contains.docx
 
3) why did you collect the aqueous layer inthe extraction- Dont organi.docx
3) why did you collect the aqueous layer inthe extraction- Dont organi.docx3) why did you collect the aqueous layer inthe extraction- Dont organi.docx
3) why did you collect the aqueous layer inthe extraction- Dont organi.docx
 
3 of 17 Problem 11-31 A mass is oscillating with amplitude A at the en.docx
3 of 17 Problem 11-31 A mass is oscillating with amplitude A at the en.docx3 of 17 Problem 11-31 A mass is oscillating with amplitude A at the en.docx
3 of 17 Problem 11-31 A mass is oscillating with amplitude A at the en.docx
 
4) The mold production equipment that uses impeller blades to -ing san.docx
4) The mold production equipment that uses impeller blades to -ing san.docx4) The mold production equipment that uses impeller blades to -ing san.docx
4) The mold production equipment that uses impeller blades to -ing san.docx
 
4) Get a medium test tube and fill it with about 5 mL of water and a f.docx
4) Get a medium test tube and fill it with about 5 mL of water and a f.docx4) Get a medium test tube and fill it with about 5 mL of water and a f.docx
4) Get a medium test tube and fill it with about 5 mL of water and a f.docx
 
4) (30 pts) What is pH of (show all your work) A) 0-038 M solution of.docx
4) (30 pts) What is pH of (show all your work) A) 0-038 M solution of.docx4) (30 pts) What is pH of (show all your work) A) 0-038 M solution of.docx
4) (30 pts) What is pH of (show all your work) A) 0-038 M solution of.docx
 
3x + (-3y) - (4x) + y -Solution -3x + (-3y) - (4x) + y -3x-(4x) + (-3.docx
3x + (-3y) - (4x) + y -Solution -3x + (-3y) - (4x) + y  -3x-(4x) + (-3.docx3x + (-3y) - (4x) + y -Solution -3x + (-3y) - (4x) + y  -3x-(4x) + (-3.docx
3x + (-3y) - (4x) + y -Solution -3x + (-3y) - (4x) + y -3x-(4x) + (-3.docx
 
37) The Schwarzschild radius of a black hole is that radial distance f.docx
37) The Schwarzschild radius of a black hole is that radial distance f.docx37) The Schwarzschild radius of a black hole is that radial distance f.docx
37) The Schwarzschild radius of a black hole is that radial distance f.docx
 
36- During the year ended December 31- 2015- Anderson Hospital (operat.docx
36- During the year ended December 31- 2015- Anderson Hospital (operat.docx36- During the year ended December 31- 2015- Anderson Hospital (operat.docx
36- During the year ended December 31- 2015- Anderson Hospital (operat.docx
 
32- What is the formula for hydrosulfuric acid- What is the formula fo.docx
32- What is the formula for hydrosulfuric acid- What is the formula fo.docx32- What is the formula for hydrosulfuric acid- What is the formula fo.docx
32- What is the formula for hydrosulfuric acid- What is the formula fo.docx
 
30- Higher speed image receptors generally produce images with a) Bet.docx
30- Higher speed image receptors generally produce images with  a) Bet.docx30- Higher speed image receptors generally produce images with  a) Bet.docx
30- Higher speed image receptors generally produce images with a) Bet.docx
 
Problem 3 Given 5-81 g of C11H22011- calculate the following- moles of.docx
Problem 3 Given 5-81 g of C11H22011- calculate the following- moles of.docxProblem 3 Given 5-81 g of C11H22011- calculate the following- moles of.docx
Problem 3 Given 5-81 g of C11H22011- calculate the following- moles of.docx
 
QUESTION 11 Another name for the spread in a Eurocurrency loan is the.docx
QUESTION 11 Another name for the spread in a Eurocurrency loan is the.docxQUESTION 11 Another name for the spread in a Eurocurrency loan is the.docx
QUESTION 11 Another name for the spread in a Eurocurrency loan is the.docx
 
QUESTION 1 The following complex is yellow in color What color of ligh.docx
QUESTION 1 The following complex is yellow in color What color of ligh.docxQUESTION 1 The following complex is yellow in color What color of ligh.docx
QUESTION 1 The following complex is yellow in color What color of ligh.docx
 
Propane (molar mass 44-11 g-mol) boils at -42-1C- Ethanol has almost t.docx
Propane (molar mass 44-11 g-mol) boils at -42-1C- Ethanol has almost t.docxPropane (molar mass 44-11 g-mol) boils at -42-1C- Ethanol has almost t.docx
Propane (molar mass 44-11 g-mol) boils at -42-1C- Ethanol has almost t.docx
 
QUESTION 1 1 points S Saved What is the concentration of H2S in a satu.docx
QUESTION 1 1 points S Saved What is the concentration of H2S in a satu.docxQUESTION 1 1 points S Saved What is the concentration of H2S in a satu.docx
QUESTION 1 1 points S Saved What is the concentration of H2S in a satu.docx
 

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Recently uploaded (20)

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 

PYTHON- Write a function findMaxDiff() that takes a two-dimensional li.docx

  • 1. PYTHON: Write a function findMaxDiff() that takes a two-dimensional list of positive integers as a parameter. It prints the index of the row with the maximum difference between elements as well as the value of the maximum difference in that row. The maximum difference between elements in a row is defined to be the difference between the largest and smallest elements in the row. The function must not modify the list passed as a parameter. You may assume that each sublist in the parameter has at least one item in it. If there are multiple sublists that all achieve the maximum difference, the first sublist should be reported as the one with the maximum difference. T Solution def findMaxDiff(lst): "Input:list(int); Output: (int, int)" answer = [] index = max(range(len(lst)), key=lambda i: sum(lst[i])) holder = enumerate(max(x) - min(x) for x in lst) return max(x[::-1] for x in holder) return index