python - Getting <generator object <genexpr> -
i have 2 lists:
first_lst = [('-2.50', 0.49, 0.52), ('-2.00', 0.52, 0.50)] second_lst = [('-2.50', '1.91', '2.03'), ('-2.00', '1.83', '2.08')]
i want following math it:
multiply 0.49
1.91
(the corresponding values first_lst
, second_lst
), , multiply 0.52
2.03
(corresponding values also). want under condition values @ position 0
in each corresponding tuple idential -2.50
== -2.50
etc. obviously, same math remaning tuples well.
my code:
[((fir[0], float(fir[1])*float(sec[1]), float(fir[2])*float(sec[2])) fir in first_lst) sec in second_lst if fir[0] == sec[0]]
generates object:
[<generator object <genexpr> @ 0x0223e2b0>]
can me fix code?
you need use tuple()
or list()
convert generator expression list
or tuple
:
[tuple((fir[0], fir[1]*sec[1], fir[2]*sec[2]) fir in first_lst)\ sec in second_lst if fir[0] == sec[0]]
working version of code:
>>> first_lst = [tuple(float(y) y in x) x in first_lst] >>> second_lst = [tuple(float(y) y in x) x in second_lst] >>> [((fir[0],) + tuple(x*y x, y in zip(fir[1:], sec[1:]))) \ fir in first_lst sec in second_lst if fir[0]==sec[0]] [(-2.5, 0.9359, 1.0555999999999999), (-2.0, 0.9516000000000001, 1.04)]
Comments
Post a Comment