0

I'm wondering how to find the position of a proper noun in a list in Python. I'm aware of how to find the position of a particular word in a list like this:

for position, item in enumerate(list):
    if item == 'word':
        print position

ideally I would like to be able to find the position of the proper nouns in the text and then find the nearest proper noun to the 'word'.

Any help would be great, thank you.

user2390182
  • 72,016
  • 6
  • 67
  • 89
Jack
  • 1

2 Answers2

1

Wouldn't you just need to find if the first letter if capitalized? If that is the case, and no other rules apply, this is quite simple:

for position, item in enumerate(list):
    if item[0].upper() == item[0]:
        print position
Shovalt
  • 6,407
  • 2
  • 36
  • 51
0

You can use the nltk toolkit and its Part-Of-Speech tagger. Have a look at the accepted answer here for an example.

Community
  • 1
  • 1