-1

I'm not very used to work with python and I was asked to write this code as a list comprehension.


joacokp
  • 29
  • 4
  • 1
    Possible duplicate of [What does "list comprehension" mean? How does it work and how can I use it?](https://stackoverflow.com/questions/34835951/what-does-list-comprehension-mean-how-does-it-work-and-how-can-i-use-it) – mkrieger1 Nov 15 '19 at 19:18

2 Answers2

0

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)]
Adam Roman
  • 87
  • 5
0
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

k2a
  • 51
  • 1
  • 6