+ 1

Please help

The user enters a string. Convert the string to a list. Change the first element of the list to a different string. Iterate over the given list. In each iteration, output to the console the element from the list, the value of which is taken by the loop variable, and information about the number of characters in this element.

8th Dec 2022, 1:31 PM
Павел
Павел - avatar
4 Respostas
+ 3
# Define the input string string = "Hello, world!" # Convert the string to a list string_list = string.split() # Change the first element of the list string_list[0] = "Hi" # Iterate over the list for elem in string_list: # Output the element and the number of characters in it print(f"Element: {elem}, Number of characters: {len(elem)}") https://code.sololearn.com/c9uuuXeujeLG/?ref=app
8th Dec 2022, 2:23 PM
Calviղ
Calviղ - avatar
+ 8
Calviղ . it is not seen as a helpful behavior when we are going to post a code, as long as the op has not shown his attempt here. it is helpful to give hints and tips, so that the op has a chance to find a solution by himself.
8th Dec 2022, 7:42 PM
Lothar
Lothar - avatar
0
Thank you🌚
8th Dec 2022, 2:24 PM
Павел
Павел - avatar
0
I understand. But I can't always understand what is required. That's why I'm asking. And with an example, I already understand what's what.
8th Dec 2022, 7:46 PM
Павел
Павел - avatar