Check if string in the exact form of “<int1>,<int2>” in Python, without using regex, or try/catch
Question: I'm converting a string of two integers into a tuple. I need to make sure my
string is formatted exactly in the form of:

    
    
    "<int1>,<int2>"
    

This is not a duplicate to an earlier question. Since that did not address
restrictions I did not know about earlier. My parameter will be "4,5" for
example. I'm not allowed to write other helper functions to check if they are
formatted correctly. The checks must be done in a single function called
convert_to_tuple

I just looked at the project specs again, and I'm not allowed to import any
new modules, so regex is off the table. I'm also not allowed to use try/catch
either.

Can you point me in the write direction? Thanks

Here is my code for converting the string into a tuple. So I need some type of
check for executing this code.

    
    
    if foo: 
    s1 = "12,24"
    string_li = s1.split(',')
    num_li = [int(x) for x in string_li]
    num_tuple = tuple(num_li)
    return num_tuple
    
    else:
    empty_tuple = ()
    return empty_tuple
    


Answer: Does this work? (Edited to meet OP's requirements)

    
    
    def is_int(string):
        return string and set(string).issubset(set('1234567890'))
    
    def check_str(s):
        parts = s.split(',', 1)
        return len(parts) == 2 and is_int(parts[0]) and is_int(parts[1])
    

