lundi 22 février 2021

How to add or subtract the elements of a list to a variable depending on their value?

How to add or subtract the elements of a list to a variable depending on their value in Python? Is there any way to do it?

Note: The value of the elements in the list and the length of the list does not remain constant.

For example:

thislist = [1,4,6,10,18]
x = 5

If the value of any element in the list is >= 5, I would like to subtract x from the element. Otherwise (if the value of any element is lower than 5), I would subtract the element from x.

Aucun commentaire:

Enregistrer un commentaire