Get the output | R Interview Question | Zomato

Question

TDM = [‘The’,’Data’,’Monk]
a. Print the last object of the list
b. Change the last element to Monkey
c. Remove Monkey from the list
d. GET Monk back to the list

They did not use The Data Monk as example 😛

in progress 0
TheDataMonk 55 years 1 Answer 812 views Grand Master 0

Answer ( 1 )

  1. Solution in Python:

    TDM = [‘The’,’Data’,’Monk’] #List

    #to display the last element
    print(TDM[2])
    Output: ‘Monk’

    #to change the last element to Monkey
    TDM[2] = ‘Monkey’
    Output: [‘The’, ‘Data’, ‘Monkey’]

    #to remove Monkey from the list
    TDM.remove(‘Monkey’)
    Output: [‘The’, ‘Data’]

    #to get Monk back to the list
    TDM.append(‘Monk’)
    print(TDM)

    Output: [‘The’, ‘Data’, ‘Monk’]

Leave an answer

Browse
Browse