Implement an integer parser
Python 3 (68)

s=input()
n=s&lt;'0'
t=0
for c in s[n:]:t=t*10+ord(c)-48
print(t-t*2*n)


The Boolean n remembers whether the string started with a minus sign by using the lexicographic string ordering, in which '-' is less then the lowest digit '0'. The expression s[n:] casts n to a number (0 or 1), skipping the minus sign if it was there. The expression t-t*2*n is a shortening of [t,-t][n].