'Iterate Over List and Deduct Random Value from Time Values

I have a long list of NamedTuples which contain time values. Extract below. I want to iterate over the list and deduct a random value from each time value. ie a different random number for each time value.

The problem is that sometimes the random value deducted results in a sleep length must be non-negative error.

How can I first test whether the result of the random value deduction would lead to a negative number and skip deducting the random value from that particular time value?

List extract:

list_one = [Test(a=820, b=625, time=1643282249.9990437), Test(a=820, b=624, time=1643282250.0470896), Test(a=820, b=623, time=1643282250.1034527), Pass(test_type='do1', pass='ffg3', time=1643282250.7834597)]

Code:

randomise = lambda: random.randint(-5, 5)
randomise_time = lambda: random.uniform(0.01, 0.001)
list_one = [Test(t.a + randomise(), t.b + randomise(), t.time - randomise_time()) if isinstance(t, Test) else t for t in list_one]


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source