Andrea Capone
Andrea Capone

Reputation: 31

min() arg is an empty sequence with error index

Sorry, I'm troubled, I have the sequent suggestion!

lista_yi_da_attiv.append (1+lista_ratio.index(min(x for in lista_ratio if x is not 0)

returns a sequent

ValueError: min() arg is an empty sequence

Upvotes: 2

Views: 4903

Answers (3)

SparkAndShine
SparkAndShine

Reputation: 18007

In your case, min(x for in lista_ratio if x is not 0) might equals to min([]) (the argument is an empty sequence) that raises ValueError

>>> min([])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: min() arg is an empty sequence

Specify a default value for max and min to avoid such exceptions caused by an empty sequence. For instance,

min(list or [0]) # default vaule is 0

Python3.4 adds a default keyword argument to max and min. For instance,

>>> min([], default=0)
0

Upvotes: 4

Louis
Louis

Reputation: 2890

When your x=0 you don't have an index and can't add.

Upvotes: 0

konstov
konstov

Reputation: 56

May be

lista_yi_da_attiv.append(1+lista_ratio.index(min([x for x in lista_ratio if x != 0])

Upvotes: 1

Related Questions