Skip to content

Commit a04240c

Browse files
authored
feat(solutions): slugify/python/function (#16)
1 parent df539a4 commit a04240c

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# slugify/python/function
2+
3+
Created by [@Mehln](https://github.com/Mehln) on 14 October 2022.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
string = input()
2+
3+
def isalphanum(character: str)->bool:
4+
is_lowercase_letter = ord(character) >= ord('a') and ord(character) <= ord('z')
5+
is_upper_letter = ord(character) >= ord('A') and ord(character) <= ord('Z')
6+
is_digit = ord(character) >= ord('0') and ord(character) <= ord('9')
7+
return is_upper_letter or is_lowercase_letter or is_digit
8+
9+
string = string.strip(' ')
10+
string = string.strip('-')
11+
answer = ""
12+
current = ""
13+
14+
for character in string:
15+
if character == ' ' or (character == '-' and len(current)>0):
16+
answer += current
17+
answer += '-'
18+
current = ""
19+
elif isalphanum(character):
20+
current += character
21+
22+
answer += current
23+
24+
print(answer)

0 commit comments

Comments
 (0)