Hello, why do we have to assign row[0] and row[1] to variables? Why does Python not allow me to write the code as swap_avg_by_hour.append([row(1), row(0)])?
Hi @vroomvroom,
This is because you are using ()
instead of []
.
swap_avg_by_hour.append([row(
1)
, row(
0)
])
When you use ()
, python interpreter thinks that you are trying to call a function named row
. Here is an example on how to do it without getting an error:
>>> dataset = [[1,2,3], [4,5,6], [7,8,9]]
>>> new_list = []
>>>
>>> for row in dataset:
... new_list.append([row[0], row[1]])
...
>>> new_list
[[1, 2], [4, 5], [7, 8]]
>>>
2 Likes