For example:
a = [1,2,3,4,5,6]
I want to do:
1/2/3/4/5/6
I have tried using the operator.div
function but it doesn't seem to give the correct result. By the way, I am fairly new to python.
For example:
a = [1,2,3,4,5,6]
I want to do:
1/2/3/4/5/6
I have tried using the operator.div
function but it doesn't seem to give the correct result. By the way, I am fairly new to python.
You can use
reduce
.The code can be demonstrated as
which is equivalent to
As
truediv
has already been demonstrated by the other answer, this is an alternative (the other way is preferred) for Python2Why not just use a loop?
You can use
reduce()
andoperator.truediv
:Note: In python3.x you need to import the
reduce()
function from fromfunctools
module.