Search min () / max () for a "large" list in python. ValueError: min () arg - empty sequence

I have a list of lists: E [] [], where E has ten subscriptions, each of which has about 500 entries.

My main task is to calculate the maximum of all 5000 values ​​that are distributed in ten signatures.

Now I wrote the following:

MinVal = min(min(E[i]) for i in range(len(E)))

and he gave me this error: ValueError: min () arg is an empty sequence

Now I wrote this:

min_arr = []
for i in range(len(E)):
    min_arr.append(min(E[i]))
MinVal = min(min_arr)

and it gives me the same error: ValueError: min () arg is an empty sequence

So, I just try to do this:

print(max(E[1]))

and he gives me an answer

The first two codes also work for small lists of items 5-10 . But it shows a problem with large data sets.

What should I do?

+4
2

:

MinVal = min(min(E[i]) for i in range(len(E)))

E[i] == [], . -. :

min_val = min(min(e) for e in E if e)

:

min_vals = []
for e in E:
    if e: # or 'if e != []:' - empty sequences evaluate False-y
        mins.append(min(e))
min_val = min(min_vals)

( , i , E.)

5 000 , , , .

+3

, :

MinVal = min(i for sublist in E for i in sublist)

, , , , .

, , . "":

minimum = float('inf')
maximum = float('-inf')
for sublist in E:
    for i in sublist:
        if i < minimum:
            minimum = i
        if i > maximum
            maximum = i

, .

+1

All Articles