How to find the maximum digit of an integer?

Question:

If the integer is 2013, then the maximum number would be 3.

How would I proceed to doing so?

Asked By: user1814771

||

Answers:

max([int(c) for c in str(2013)])

First you convert the number to a string, this allows to look at every digit one by one, then you convert it into a list of single digits and look for the maximum.

Another solution is

max = -1

for c in str(2013):
    i = int(c)
    if i > max:
        max = i
Answered By: peter
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.