MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / remove_digit

Function remove_digit

maths/remove_digit.py:1–33  ·  view source on GitHub ↗

returns the biggest possible result that can be achieved by removing one digit from the given number >>> remove_digit(152) 52 >>> remove_digit(6385) 685 >>> remove_digit(-11) 1 >>> remove_digit(2222222) 222222 >>> remove_digit("2222222") Traceba

(num: int)

Source from the content-addressed store, hash-verified

1def 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
36if __name__ == "__main__":

Callers

nothing calls this directly

Calls 1

popMethod · 0.45

Tested by

no test coverage detected