0

List Slices

Hey guys I know this is probably really simple. I have looked through other discussion board about this challenge but have been unable to see any possible solutions. Question is: Write a program that takes a list as input and outputs the last element of that list. The input list can be of any size. Answer I came up with is: x = input() elements = x.split() print(elements[-1::]) only issue I have is that when it prints the output it comes up like ['6'] and I cannot for the life of me think of how to remove the quotations and []. Thanks in advance.

10th Jun 2021, 9:00 PM
Jairrid Brown
Jairrid Brown - avatar
1 Resposta
+ 4
you are not getting the last element but a sublist from last element to end of list (a list with a unique element): remove the colon to get only the element ;)
10th Jun 2021, 9:09 PM
visph
visph - avatar