Finding the insertion point in a list

Paul Rubin http
Fri Mar 16 22:17:08 EDT 2007


tkpmep at hotmail.com writes:
> Or with a generator comprehension
> n  = sum ( y>x[i] for i in range(len(x)) ) - 1
> 
> But there  has to be a cleaner way, as the first approach is unwieldy
> and does not adapt to changing list lengths, and the second is not
> obvious to a casual reader of the code.

How about:

  n = len([y > t for t in x])



More information about the Python-list mailing list