Try:
lst = [1, 2, 3, 4, 5, 6, 7]
out = [sum(vv < v for vv in lst[:i]) for i, v in enumerate(lst)]
print(out)
Prints:
[0, 1, 2, 3, 4, 5, 6]
4
solved How to find the count of numbers that are less than each element of a list [closed]
Try:
lst = [1, 2, 3, 4, 5, 6, 7]
out = [sum(vv < v for vv in lst[:i]) for i, v in enumerate(lst)]
print(out)
Prints:
[0, 1, 2, 3, 4, 5, 6]
4
solved How to find the count of numbers that are less than each element of a list [closed]