python - raise dict keys to the power of their value and multipy together quickly -


i'm trying take dictionary , (1) raise each key power of value, , (2) multiply results of (1).

this needs done several million rows of data. thoughts on how speed process? using pandas data frame's map function apply function totheexp column of data already. step still pretty slow though. i'm trying like:

import ast numpy import array functools import reduce import operator  def totheexp(d):     return reduce(operator.mul, array(d.keys())**array(d.values()), 1)  totheexp({2:3,4:5,6:7}) >>> 2293235712 

what using comprehension, example:

from functools import reduce operator import mul  print(reduce(mul,(k**v k,v in {2:3,4:5,6:7}.items()),1) #2293235712 

Comments

Popular posts from this blog

Prolog - Listing -

python - can't seem to get an output from my class -

orchardcms - change base url in local copy in Orchard CMS -