<jupyter_start><jupyter_text>Pair Problem*A version of this problem was faced at a whiteboard by a Metis student in an interview for a data scientist position on April 16, 2015.*In programming languages, and especially in Lisps, there can be a lot of parentheses. The parentheses have to be "balanced" to be valid. For example, `()(())` is balanced, but `()())` is not balanced. Also, `)((())` is not balanced.Write a function that takes a string and returns `True` if the string's parentheses are balanced, `False` if they are not.**This is fairly easy. Once you are finished, see if you can come up with a second way to solve the problem.**Here are examples to test your function with: * `(()()()())` should return `True` * `(((())))` should return `True` * `(()((())()))` should return `True` * `((((((())` should return `False` * `()))` should return `False` * `(()()))(()` should return `False`<jupyter_code>def lisp_simple(s):
    if not s.count("(") == s.count(")"): # Check that open and close parantheses match
        return False
    left = 0                             # Check that there are never more close than open parantheses
    right = 0
    for i in s:
        if i == "(":
            left += 1
        if i ==")":
            right += 1
            if right > left:
                return False
    return True
ex1 = "()((ddfsaf))"
ex2 = "()())"
ex3 = ")((())"
ex4 = "(((((()"
ex5 ="(()()()())"
lisp_simple(ex1)
lisp_simple(ex2)
lisp_simple(ex3)
lisp_simple(ex4)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16105610561056105, 'fraction_numerical': 0.012541254125412541, 'mean_word_length': 3.3068181818181817, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '658457', 'license': 'MIT', 'n_tokens_mistral': 474, 'n_tokens_neox': 451, 'n_words': 184, 'path': 'pair_programming_exercises/Pair Programming - Day 16.ipynb', 'repo_name': 'athena15/metis', 'size': '1515'}