How do I find the max integer of a string of integer without using a list?
<p>I must use a for loop, no list allowed. May assume string is non-empty. What I have:</p>

<pre><code>def max_numbers(s):
    n_string = ''
    for char in s:
        if char.isdigit():
            n_string += char
    return max(n_string)

max_numbers('22  53 123 54 243')
5
expected 243
</code></pre>

<p>Please don't use any advance methods, I am still a beginner. I wanted 243 to show up but ended up with 5 instead.</p>

<p>Not going to write any code for you because doing it the way you have specified is just boring. Also since you have not indicated what version of python you are using, I will just assume version 2.</p>

<p>Here are a few things you will need:</p>

<ul>
<li><a href="https://docs.python.org/2/library/stdtypes.html#str.isspace" rel="nofollow"><strong>str.isspace()</strong></a> Use this to determine when you have reached a space</li>
<li><a href="https://docs.python.org/2/library/stdtypes.html#str.isdigit" rel="nofollow"><strong>str.isdigit()</strong></a> Use this to determine when you have read a number</li>
<li><a href="https://docs.python.org/2/library/functions.html#int" rel="nofollow"><strong>int()</strong></a> Use this to convert a string number to integer</li>
</ul>

<h2>The algorithm goes like this:</h2>

<ol>
<li><p>First initialize a variable called <code>num</code> to the empty string</p></li>
<li><p>Read digits until you either reach the end of the string or reach a non digit. Each digit read should be appended to <code>num</code></p></li>
<li>If you reach a space or end of the string and <code>neg</code> is not empty, use <code>int</code> to convert <code>num</code> to an integer otherwise skip to step 5</li>
<li>Compare this value to your current max and replace max with the value if it is larger</li>
<li>Repeat from step 1 if you have not reached the end of the string</li>
<li>Finally print your current max</li>
</ol>

<h2>Special case to handle negative numbers</h2>

<ol>
<li>Initialize a variable called <code>num</code> to the empty string and a variable called <code>neg</code> to <code>1</code></li>
<li>If the first thing read is not a digit and is not space but is the <code>-</code> character, set <code>neg</code> to <code>-1</code> otherwise read digits until you either reach the end of the string or reach a non digit. Each digit read should be appended to <code>num</code></li>
<li>If you reach a space or end of the string and <code>num</code> is not empty, use <code>int</code> to convert <code>num</code> to an integer; otherwise skip to step 6</li>
<li>Multiply this integer by <code>neg</code></li>
<li>Compare this value to your current max and replace max with the value if it is larger</li>
<li>Repeat from step 1 if you have not reached the end of the string</li>
<li>Finally print your current max</li>
</ol>

<hr>

<p>The non boring version:</p>

<pre><code>print (max(map(int, my_str.split())))
</code></pre>

python