Let\'s say I have a list of names :
names = [\'King ARTHUR\',
\'Lancelot The brave\',
\'galahad the pure\',
\'Servant patsy\',
You can use string methods. If you encounter a 'the' in any form, you just put it into lower case. Every other part of the string is assumed to be a name and is capitalized.
names = list(set([' '.join(i.lower() if i.lower() == 'the' else i.capitalize() for i in name.split())
for name in names]))
This uses the join() method to merge the modified parts of the string again and builds a new list based on the names list. To eliminate duplicates, the set function is used, finally the set is converted back to a list.