-4

thanks for looking. I'm still working on my named entity recognition project, and I'm almost done. My project was to extract all the names of people from a long string, and I've gotten to the point where I have a list of names, which I have named ent3.

This list has some artifacts from previous processing that are incorrect. Specifically, I have elements in the list like 'Josie husband' or 'Laura fingernail'. I want to eliminate those elements completely.

Is there a way to make Python iterate over the list and remove any elements that contain an UNcapitalized word?

Jack Harris
  • 245
  • 4
  • 13
  • 2
    It would be a very odd limitation on Python if it was impossible to use it to remove elements from a list that have uncapitalized words. – John Coleman Dec 13 '19 at 17:14
  • The answer to "is it possible" is usually "yes" -- you're using a general-purpose language on a general-purpose computer, so you have full Turing potential. The implied question behind this, "how do I do it?" is an open-ended, individualized tutorial, which is *seriously* off-topic for Stack Overflow -- please re-take the [intro tour](https://stackoverflow.com/tour). – Prune Dec 13 '19 at 17:14
  • If you search in your browser for "Python find capitalized words", you'll find references that can explain this much better than we can manage here. – Prune Dec 13 '19 at 17:14
  • if you import `from string import ascii_uppercase`, then you can do something like: `[w for w in world_list if all(l in ascii_uppercase for l in w)]` – Brian Dec 13 '19 at 17:17

1 Answers1

1

Here we are

names = [
    'Jose Maria',
    'Alex Qqq',
    'Alex daddy',
    'Maria Fernandez',
    'Joe Dohn',
    'Dani mother'
]

clean = [x for x in names if not any((word.lower() == word for word in x.split()))]

print(clean)

Outputs

['Jose Maria', 'Alex Qqq', 'Maria Fernandez', 'Joe Dohn']
Alexandr Shurigin
  • 3,921
  • 1
  • 13
  • 25