How to print the last let us say 10 elements of an array containing 50 ekements ?

The code in python 3:

x = [‘a’,’b’,’c’,’d’,’e’,’f’,’g’]

n = 5

y =[ ]

i = 0

while (i<n) :

    i+=1;

    y.append(x[-i])

print(y)

Simple !

Note : index of -1 gives last element of an array

Advertisements