1'''RETURN EVOLUTION RATE FOR A LIST (WITH COMPREHENSION)'''
2
3nums = [120,150,230,190]
4
5#LISTE COMPREHENSION
6rates = [((nums[i+1] - nums[i]) / nums[i]) for i in range(len(nums)-1)]
7rates.insert(0, np.nan)
8
9print(rates)
10>>> [nan, 0.25, 0.53.., -0.17..]
11
12#STANDARD
13rates = []
14for i in range((len(nums)-1)):
15 rates.append( (nums[i+1] - nums[i]) / nums[i] )
16rates.insert(0,np.nan)
17
18print(rates)
19>>> [nan, 0.25, 0.53.., -0.17..]