How to annotate last item in line graph

Hello I am generating a line graph that has an unknown number of (x,y) elements. How can I annotate the last item without knowing the number of elements?

In this code example (Line Charts). The last index (index 11) is very clearly referenced. Is there some more generic way to do this e.g. y_trace[last element]?

annotations.append(dict(xref=‘paper’, x=0.95, y=y_trace[11],
xanchor=‘left’, yanchor=‘middle’,
text=’{}%’.format(y_trace[11]),
font=dict(family=‘Arial’,
size=16),
showarrow=False))

Thank you!

@dbansal

The last element of a list or 1D- array has the index -1. Hence, in your case,set:
y=y_trace[-1]

Thank you, knew it had to be something like that. Will try and let you know!

Hey @empet - thanks for the tip - as always this is very useful and in line with some of the best practices. Is there a way to extend this to only annotate the last weeks data when we are looking at the last year/ months data?

Cheers
Ananth