using python 3 Write function, listyMax(listOfLists), that takes as input a list
ID: 3667993 • Letter: U
Question
using python 3
Write function, listyMax(listOfLists), that takes as input a list of zero or more sublists each containing zero or more numbers, and determines and prints the maximum number among all of the lists and the sublist containing that maximum number.
You may assume there is no tie for the maximum. I.e, if there is a maximum, it is unique. If, however, there is no maximum, listyMax should print an appropriate message.
For example:
NOTE: You may not use built-in functions min, max, sort or sorted for this problem. You need to step through the lists to find the appropriate items and do necessary basic comparisons.
Explanation / Answer
Here is the code for you:
#!/usr/bin/python
def listyMax(listOfLists):
max = listOfLists[0][0]
for i in range(0,len(listOfLists)):
for j in range(0, len(listOfLists[i])):
if(listOfLists[i][j] > max):
max = listOfLists[i][j]
listNum = i
return max, listNum
list = [[7,6], [4, 9, 6]]
x, y = listyMax(list)
print 'in',list," the max item is ",x," and is found in sublist ",list[y]
If you need any further refinements, just get back to me.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.