If the initial list is less than 10 elements, then this solution will still work yielding the whole list. E.g. if my_list = [1,2,3], then my_list[-10:] is equal to [1,2,3]
This shows how to chop a long list into a maximum size and put the rest in a new list. It's not exactly what you're asking about, but it may be what you really want:
Actually, the subscript in the statement of your question works perfectly — could you paste in exactly what error or unexpected result you are seeing when you try using it yourself? Here is a successful run of the subscript you suggest:
Is the problem simply that you forgot to name my_list in front of your slice notation?
Edit: As Felix notes, you should prevent the index from going negative:
my_list[max(0, len(my_list) - 10):]
And, of course, as the other answers note, a constant negative index is actually the easiest way to accomplish your goal; but I wanted to first focus on why your “own way” of getting the last ten elements — which made sense, even if it did not take full advantage of Python's conventions regarding slices — was giving you an error instead.