You are using a generator expression in your list comprehension expression:
(float(a[i][j]) for j in range(0,3))
If you wanted that to execute like a list comprehension, make that a list comprehension too:
[[float(a[i][j]) for j in range(3)] for i in range(2)]
If you need those to be tuples, then you'll have to explicitly call tuple()
:
[tuple(float(a[i][j]) for j in range(3)) for i in range(2)]
The tuple()
callable will drive the generator expression to produce a tuple of those values. There is no such thing as a tuple comprehension, otherwise.
Rather than use ranges, you can loop over a
and the nested lists directly:
[tuple(float(v) for v in nested) for nested in a]
Demo:
>>> a=[['1','3','2'],['11','22','33']]
>>> [tuple(float(v) for v in nested) for nested in a]
[(1.0, 3.0, 2.0), (11.0, 22.0, 33.0)]