Jan-08-2019, 05:37 AM
(Jan-07-2019, 10:56 PM)Petrus Wrote: No, I just want to multiply every single value inside the list with each other.
Two possible ways to achieve that below. It is recommended to keep what you do and how you do separate. Therefore functions are used:
# without any import def sequence_product(sequence): """Return sequence elements product; if empty return zero.""" if not sequence: return 0 else: total = 1 for el in sequence: total *= el return total # with reduce and mul from functools import reduce from operator import mul def sequence_product(sequence): """Return sequence elements product; if empty return zero.""" if not sequence: return 0 else: return reduce(mul, sequence)
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.