Embrace Change and Strive for Success with Short Names Transformation

How can you modify a list of short names to achieve a specific outcome?

Given the sample output with input: 'Gertrude Sam Ann Joseph'

Answer:

Here is the solution for the given question. Modify short_names by deleting the first element and changing the last element to Joe:

In this code, first, we are taking the user_input from the user and then splitting the entered input into words or string using .split() function. The split() function separates the input string into a list of string elements where each word is a separate string element in the list. Now, we are modifying the short_names list by deleting the first element of the list using the pop() method which removes and returns the last element of the list.

And then changing the last element to "Joe" by using -1 index as -1 refers to the last element of the list. Then finally, print the short_names list which contains only the names from the second name onwards and the last name as Joe as required.

← Best practices for seo friendly html websites How silicon valley companies have changed the game with their networks →