I thought I understood python's pass-by-reference processing... Why is there a difference between pass-by-reference for lists vs. that for list elements, specially if both are objects as far as I understand it:
dataBloc = [ ['123'] , ['345'] ]
print dataBloc
def func( b ):
print ( 'Row-by-Row Before' , b )
for row in b:
row = [ float(x) for x in row ]
print ( 'Row-by-Row After' , b )
print ( 'Element-by-Element Before' , b )
for row in b:
for i in range(len(row)):
row[i] = float(row[i])
print ( 'Element-by-Element After' , b )
return b
print func(dataBloc)
[['123'], ['345']]
('Row-by-Row Before', [['123'], ['345']])
('Row-by-Row After', [['123'], ['345']])
('Element-by-Element Before', [['123'], ['345']])
('Element-by-Element After', [[123.0], [345.0]])
[[123.0], [345.0]]
Thanks.
for i, row in enumerate(b): b[i] = [float(x) for x in row]. The result will be almost the same as the "element-by-element" version, though it will create new inner lists instead of reusing the old ones. - Blckknght