I want to divide a tuple by an integer. I am expecting something like this:
tuple = (10,20,30,50,80)
output = tuple/10
print(output)
output = (1,2,3,5,8)
Basically the same as this answer by Truppo.
>>> t = (10,20,30)
>>> t2 = tuple(ti/2 for ti in t)
>>> t2
(5, 10, 15)
may be you could try if is a numbers tuple:
numberstuple = (5,1,7,9,6,3)
divisor= 2.0
divisornodecimals = 2
value = map(lambda x: x/divisor, numberstuple)
>>>[2.5, 0.5, 3.5, 4.5, 3.0, 1.5]
valuewithout_decimals = map(lambda x: x/divisornodecimals, numberstuple)
>>>[2, 0, 3, 4, 3, 1]
or
value = [x/divisor for x in numberstuple]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With