-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathWord_a10n_abbreviation.py
More file actions
35 lines (29 loc) · 883 Bytes
/
Word_a10n_abbreviation.py
File metadata and controls
35 lines (29 loc) · 883 Bytes
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
# kata:
# https://www.codewars.com/kata/5375f921003bf62192000746/
# --------------------------------------------------
# Solution:
def abbreviate(s):
if len(s) > 3:
temp = []
word = ''
result = ''
for ch in s:
if ch.isalpha():
word += ch
else:
temp.append(word)
temp.append(ch)
word = ''
temp.append(word if word else '')
for i in temp:
if len(i) > 3:
result += i[0] + str(len(i) - 2) + i[-1]
else:
result += i
return result
return s
# --------------------------------------------------
print(abbreviate("internationalization"), "i18n")
print(abbreviate("accessibility"), "a11y")
print(abbreviate("Accessibility"), "A11y")
print(abbreviate("elephant-ride"), "e6t-r2e")