I need to write a code which recognizes special names such as names for places and people cities and etc. and then it should announce the place of the word and not character. for example if the string is: 'Today Sam and Martin are happy' it should print out this: 1:Sam 3:Martin but my code writes: 0:Today 6:Sam 14:Martin here is the actual code:
import re
b=[]
x=str(input())
r =re.compile('([A-Z][a-z]+)')
a=re.findall(r, x)
a=list(a)
word=len(x.split())
b=[word for word in range(len(x)) if x[word].isupper()]
o=str([j for i in zip(b,a) for j in i])
d=o.replace(", '", ':').replace("'",'').replace(",", '\n').replace('[','').replace(']',
'').replace(' ', '')
print(d)
do you know how can I fix it?