-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbook_authors.py
36 lines (25 loc) · 1.03 KB
/
book_authors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: utf-8 -*-
def first_capital_letter(string):
prepositions = ['da', 'de', 'do', 'das', 'dos']
new_string = ''
parts = string.split(' ')
for part in parts:
if prepositions.count(part.lower()) == 1:
new_string = new_string + ' ' + part.lower()
else:
new_string = new_string + ' ' + part[0].upper() + part[1:len(part)].lower()
return new_string
def book_authors(name):
inherited_names = ['filho', 'filha', 'neto', 'neta', 'sobrinho', 'sobrinha']
if len(name) == 0:
return ''
parts = name.split(' ')
if len(parts) == 1:
return parts[0].upper()
if inherited_names.count(parts[len(parts)-1:len(parts)][0].lower()) and len(parts) >= 3:
first_names = parts[0:len(parts)-2]
last_two_names = parts[len(parts)-2:len(parts)]
names = first_names
names.append(' '.join(last_two_names))
parts = names
return parts[len(parts) - 1].upper() + ',' + first_capital_letter(' '.join(parts[0:len(parts) - 1]))