Store the alphabets and digits separately in the strings
for x in s : NEW_LINE INDENT if x . isalpha ( ) : NEW_LINE INDENT s1 . append ( x ) NEW_LINE DEDENT else : NEW_LINE INDENT s2 . append ( x ) NEW_LINE DEDENT DEDENT