-
Notifications
You must be signed in to change notification settings - Fork 0
/
nameAbbreviater.py
42 lines (36 loc) · 1.24 KB
/
nameAbbreviater.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
37
38
39
40
41
42
def abbreviateName(fullName, fNameStatement, mNameStatement, sNameStatement):
output = ""
nameLenLimit = 3
sFullName = fullName.split()
fName = sFullName[0]
sName = sFullName[-1]
if fNameStatement is True:
output += setOutputType(fNameStatement, fName[0])
else:
output += setOutputType(fNameStatement, fName[0])
# get all elements between the first and the last elements
midNames = sFullName[1:-1]
if mNameStatement is True:
if len(sFullName) >= nameLenLimit:
if len(midNames) >= 0:
for midName in midNames:
output += setOutputType(mNameStatement, midName[0])
else:
for midName in midNames:
print(output)
output += setOutputType(fNameStatement, midName)
if sNameStatement is True:
output += setOutputType(sNameStatement, sName[0])
else:
output += setOutputType(fNameStatement, sName)
print(output)
def setOutputType(short, name):
if short is False:
return name + " "
else:
return name[0] + "." + " "
fNameStatement = True
mNameStatement = True
sNameStatement = False
abbreviateName("Mustafa Kemal Demir", fNameStatement,
mNameStatement, sNameStatement)