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

MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
Krashi Coaching
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 

Recently uploaded (20)

UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
Software testing for project report .pdf
Software testing for project report .pdfSoftware testing for project report .pdf
Software testing for project report .pdf
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf
 
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
 
Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).
 
demyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxdemyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptx
 
How to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 InventoryHow to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 Inventory
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
The Ball Poem- John Berryman_20240518_001617_0000.pptx
The Ball Poem- John Berryman_20240518_001617_0000.pptxThe Ball Poem- John Berryman_20240518_001617_0000.pptx
The Ball Poem- John Berryman_20240518_001617_0000.pptx
 
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
 
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
 
Navigating the Misinformation Minefield: The Role of Higher Education in the ...
Navigating the Misinformation Minefield: The Role of Higher Education in the ...Navigating the Misinformation Minefield: The Role of Higher Education in the ...
Navigating the Misinformation Minefield: The Role of Higher Education in the ...
 
Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
Championnat de France de Tennis de table/
Championnat de France de Tennis de table/Championnat de France de Tennis de table/
Championnat de France de Tennis de table/
 
“O BEIJO” EM ARTE .
“O BEIJO” EM ARTE                       .“O BEIJO” EM ARTE                       .
“O BEIJO” EM ARTE .
 

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