-2

I need to get last three elements of the list without evaluating the length of the list. Following code displays what I expect:

sports = ['cricket', 'football', 'volleyball', 'baseball', 'softball', 'track and field', 'curling', 'ping pong', 'hockey']
last = ['curling', 'ping pong', 'hockey']
Atharva Kadlag
  • 302
  • 3
  • 15
The senix
  • 11
  • 2
  • Does this answer your question? [Understanding slice notation](https://stackoverflow.com/questions/509211/understanding-slice-notation) – sushanth Jun 12 '20 at 16:39

1 Answers1

1
last = sports[-3:]

this should do it

Atharva Kadlag
  • 302
  • 3
  • 15