0
How to find and show the position of an item in the list, not setting the string value for the search?
Ex:
nome_pessoa = str(input('Informe o seu nome completo: '))
lista_nomes = nome_pessoa.split()
After the names are divided and transformed into a list, I would like to know how, for example, to indicate the position the third name(or item) is.
Suppose that in this first execution, the user has entered the name : 'Pedro Lucas Gomes'.
That way, after transforming this string into the list with the names, it will have the items: ['Pedro', 'Lucas', 'Gomes'']
What I want in exit data, that is to say, printado on screen is:
The name of the second position, which in this case would be 'Gomes', and the position number, which will be 2.
BUT CASE AT SECOND RUN, the user type the name 'João Neves Frufru Feitosa', what I want on output is:
The name of the second position is 'Frufru', and the number of its position is 2.
Did you understand? I won’t use the command:
print(list_names.index('Frufru'))
Because the name 'Frufru' will not be fixed in the code! The name requested in the program, will be typed from the keyboard by the user at the time of each code execution.
(I thank everyone who is striving to help and I apologize for my lack of clarity before the issue)
Thank you very much for your reply, my dear, but it is not what I want, but it was almost. What I want in data output is to show the name of a given position, and the number of the position of that item. Ex: If the person’s name is 'João Mota Silva Mufino', the name of the third position that will be shown in the terminal, will be "Mufino", and the number of the position of the list that I want the program to show, will be 3. I don’t know how to tell which position number, without defining the item name first. Set the item name in the code to show its position, is what I don’t want.
– PedroLucas96