169k views
16 votes
There is a non-empty array of String's named names. Write a code segment that removes the last letter of the String stored in the very last position of names. For bragging rights and if possible (and I'm not sure if it is), write a single statement that performs this task.

1 Answer

3 votes

Answer:

Step-by-step explanation:

The following code is written in Python. It is a function called remove_last_letter that does just that, removes the last letter of the last element in the array. and saves it back into the array. The code is written in three statements but only the middle statement is the actual code, the other two are the function creation statement and the last is the return statement.

def remove_last_letter(names):

names[-1] = names[-1][0:-1]

return names

User Dmitry Baranovsky
by
3.3k points