Home > other >  Python for a list of the first in the negative position in the list
Python for a list of the first in the negative position in the list

Time:03-03

Write their own, the output is always none [face] monkey2:019 PNG [/face]
To solve the

CodePudding user response:

[x & lt; 0 for x in a]. Index (True)

CodePudding user response:

For I, x enumerate in (a) :
If x & lt; 0:
Return the I

CodePudding user response:

Your function x=0; A=[], so does not meet the conditions of the while loop the start 0 & lt; Len (a), inside a is empty

CodePudding user response:

> A
[2, 3, 1, 4, 2)
> B
[2, 3, 1, 4, 2)
> Index_num [0] the if (index_num:=[index for the index, I enumerate in (a) if i<0]) else None
2
> Index_num [0] the if (index_num:=[index for the index, I enumerate in (b) if i<0]) else None
>
  • Related