If you have a list Ns
of numbers (if it's a list of strings as in several similar questions asked recently each will have to be made into an int, or whatever other kind of number, by calling int
[[or float
, etc]] on it), the list of their absolute values (if that's what you mean by "ensure") is
[abs(n) for n in Ns]
If you mean, instead, to check whether all numbers are >= 0
, then
all(n >= 0 for n in Ns)
will give you a bool
value respecting exactly that specification.
The sum of the items of the list that are <x
is
sum(n for n in Ns if n < x)
Of course you may combine all these kinds of operations in one sweep (e.g. if you need to take the abs(n)
as well as checking if it's < x
, checking if it's >= 0
, summing, whatever).