File tree 2 files changed +27
-0
lines changed
challenges/slugify/solutions/python/function
2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+ # slugify/python/function
2
+
3
+ Created by [ @Mehln ] ( https://github.com/Mehln ) on 14 October 2022.
Original file line number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments