How to convert all first elements of a tuple in a list of tuples to positive and second to negative in Python

1 Answer

0 votes
tplList = [(-2, 3), (5, 4), (7, -9), (-1, 6)]

tplList = [(abs(val[0]), -1 * abs(val[1])) for val in tplList]

print(tplList)



'''
run:

[(2, -3), (5, -4), (7, -9), (1, -6)]

'''

 



answered Dec 4, 2022 by avibootz
...