Ad
  • Custom User Avatar

    from math import prod

  • Custom User Avatar

    But, I haven't found built-in to get the product of the list.
    Can you give the cue, please.

  • Custom User Avatar

    Wow, thanks)

  • Custom User Avatar

    You don't need to turn that generator expression into a list, you could replace the [] with () to theoretically improve performance.
    Or you could just not do any i for i in stuff and just make the second argument the list itself.
    You could also pass a 1 as a third argument to functools.reduce to simplify this a little.
    Instead of using a lambda, you could import from operator.
    Finally, instead of a reduce, you can just use a certain built-in to get the product of the list.