I'm not very used to work with python and I was asked to write this code as a list comprehension.
I'm not very used to work with python and I was asked to write this code as a list comprehension.
This would be your for loop as a list comprehension assuming the i_averaged and time_interval are referenced prior to the loop.
t_averaged = [t[i_averaged[i]] + time_interval/2 for i in range(len(i_averaged)-1)]
squares = []
for x in range(10):
squares.append(x ** 2)
# [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
using the list comprehension:
squares = [x ** 2 for x in range(10)]
# [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
try it yourself