import re s = "0207a97"l = [i for i in re.findall('\d+',s) if '9' not in i]if len(l)>0: print(max(l, key=int))
Standard input is empty
0207
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!