File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ def remove_digit (num : int ) -> int :
2+ """
3+
4+ returns the biggest possible result
5+ that can be achieved by removing
6+ one digit from the given number
7+
8+ >>> remove_digit(152)
9+ 52
10+ >>> remove_digit(6385)
11+ 685
12+ >>> remove_digit(-11)
13+ 1
14+ >>> remove_digit(2222222)
15+ 222222
16+ >>> remove_digit("2222222")
17+ Traceback (most recent call last):
18+ TypeError: only integers accepted as input
19+ >>> remove_digit("string input")
20+ Traceback (most recent call last):
21+ TypeError: only integers accepted as input
22+ """
23+
24+ if not isinstance (num , int ):
25+ raise TypeError ("only integers accepted as input" )
26+ else :
27+ num_str = str (abs (num ))
28+ num_transpositions = [list (num_str ) for char in range (len (num_str ))]
29+ for index in range (len (num_str )):
30+ num_transpositions [index ].pop (index )
31+ return max (
32+ int ("" .join (list (transposition ))) for transposition in num_transpositions
33+ )
34+
35+
36+ if __name__ == "__main__" :
37+ __import__ ("doctest" ).testmod ()
You can’t perform that action at this time.
0 commit comments