I am new to python and want to make a simple program that prints back your name and preposition in James Bond style.
So if the name contains any prepositions, such as 'Van', 'Von', 'De' or 'Di', I want the program to print it as:
{Preposition} {LastName}, {FirstName} {Preposition} {LastName} *edited
For this, I understand we need a list of the users name and of the prepositions.
a = [user input separated with the .split function]
b = [list of prepositions]
In order to find the instance of a preposition in the name, I found that the code bellow could be used:
if any(x in a for x in b):
However, I encountered a problem when trying to print the name, seeing as the preposition could be any from the aforementioned (list b). I can not find a way to print without knowing this and its location in the string. First I thought the .index function could be used, but it seems to only be capable of searching for one word, not several as needed here. The closest I can get is:
name_split.index('preposition1') # works
name_split.index('preposition1', 'preposition2', etc.) # does not work
So what I'm asking is if there is a way to check if any of the words from a list (b) is used in an inputted text, and also get the location of said word.
Hope I was able to explain it properly, and that someone could lend me some assistance. In advance; thank you.