Python Forum
Get the biggest number from a two dimensional list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get the biggest number from a two dimensional list
#11
As the error states, an empty sequence has been passed to max.
When you have an error you should show the code that resulted in the error and the full error traceback.
Reply
#12
I give up. :(
Reply
#13
Don't give up, try harder
something = [1, 2, 3, 4, 5, 6]

max_of_something = max(something)
print(max_of_something)
Output:
6
Reply
#14
This is a really easy problem that you are making hard. What is the max number in this list of lists?
[[1, 5, 6],
[8. 11, 2],
[0, 7, 3]]
The most obvious solution is the one most of us would use if presented this problem in pencil and paper, ignore the brackets and look for the biggest number.

A second solution is to find the largest number in each list, then find the biggest number of all the list maximums. This is the approach I would use on pencil and paper if there were 20 lists instead of 3.

Both of these algorithms can be converted to Python.

The "ignore the []" algorithm can be described as treating the 2D list as if all the values were in a single list. How can we do that in Python. Is there a way you can take a bunch of lists and make them into one list? I looked at "join", but that only works for strings. While looking at join I see the terms "concatenate" and append used. So I search for python list concatenate and python list append. Turns out there are lots of ways to turn a bunch of lists into a single list. Once I have a single list is is simple to find the max value.

The find the max of each list and get the max of the max's can be described as "make a list that contains the maximum value of each list. I know how to get the max value from a list. Now I just need a way to collect all those maximums and put them in another list. Turns out there are lots of ways to do that too. Once I have a list that contains the maximum values of all the other lists, getting the max of that list returns the maximum value from all the lists.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  list digit into number Voldyy 2 1,537 Jul-10-2022, 06:13 PM
Last Post: deanhystad
  Displaying list correspond to the column number danlopek14q 9 3,960 Aug-27-2021, 04:32 AM
Last Post: naughtyCat
  How to convert every even number in a list to odd? Bruizeh 4 3,757 Aug-27-2021, 03:04 AM
Last Post: naughtyCat
  How can I print the number of unique elements in a list? AnOddGirl 5 3,272 Mar-24-2020, 05:47 AM
Last Post: AnOddGirl
  Two Dimensional Arrays Coder34 1 1,900 Aug-19-2019, 10:48 AM
Last Post: buran
  Multiplying number in a list in an order pythoneer 12 6,603 Mar-23-2018, 08:21 PM
Last Post: buran
  Help with array smallest biggest number thanikos 4 3,320 Nov-30-2017, 01:06 PM
Last Post: thanikos
  adding a number to the list atux_null 4 3,868 Nov-06-2017, 07:01 PM
Last Post: gruntfutuk
  Take the biggest value from array dwiga 9 5,981 Jul-20-2017, 01:28 AM
Last Post: dwiga
  Python Exercise: Generate a two-dimensional array smbx33 4 10,833 Apr-22-2017, 11:51 PM
Last Post: smbx33

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020