dictionary - Python: eval() inside a lambda function as argument to map() changes map()'s input sequence to global() in place -
i creating new variables applying lambda functions inside of map() using python 3.4.
the input sequence map list of dicts. lambda functions defined in separate config file. minimize typing, wanted use eval() inside lambda, so:
dat = [{'a':1, 'b':2}, {'a':2,'b':1}] a_transformation = 'a > 1' temp = map(lambda x: eval(a_transformation,x), dat)
the result expected, appears each item in input sequence changed output of global()....
i can similar pandas without issues:
import pandas dat = [{'a':1, 'b':2}, {'a':2,'b':1}] dat_pandas = pandas.dataframe(a) a_transformation = 'a > 1' temp = dat_pandas.eval(a_transformation, engine='python')
but i'd prefer not have use pandas.
any ideas?
thanks!
Comments
Post a Comment