<jupyter_start><jupyter_text>Valid Parentheses (5 kyu)    https://www.codewars.com/kata/52774a314c2333f0a7000688    2020-02-11T14:10:22.780Z     Category: algorithms, Tags: ['Algorithms', 'Validation', 'Logic', 'Utilities'] Write a function called that takes a string of parentheses, and determines if the order of the parentheses is valid. The function should return `true` if the string is valid, and `false` if it's invalid. Examples```"()"              =>  true")(()))"          =>  false"("               =>  false"(())((()())())"  =>  true``` Constraints`0 <= input.length <= 100`~~~if-not:javascript,goAlong with opening (`(`) and closing (`)`) parenthesis, input may contain any valid ASCII characters.  Furthermore, the input string may be empty and/or not contain any parentheses at all.  Do **not** treat other forms of brackets as parentheses (e.g. `[]`, `{}`, ``).~~~<jupyter_code># Solution

def valid_parentheses(_str):
    valid = '()'
    stripped = ''.join([c for c in _str.strip() if c in valid])
    if len(stripped) == 0 or _str == valid:
        return True
    elif any([0 < len(stripped) <=1,
            stripped.count(')') != stripped.count('('),
            stripped.startswith(')(')
            ]):
        return False
    else:
        return valid_parentheses(stripped.replace('()', ''))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16246290801186944, 'fraction_numerical': 0.03338278931750742, 'mean_word_length': 3.422950819672131, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '465398', 'license': 'MIT', 'n_tokens_mistral': 453, 'n_tokens_neox': 405, 'n_words': 128, 'path': 'codewar/codewar.5 kyu.valid-parentheses.ipynb', 'repo_name': 'oleng/solved', 'size': '1348'}