<commit_before>from __future__ import absolute_import
from __future__ import division
from __future__ import print_function


def balance_parentheses(a_str):
    """Balance parentheses in a string."""
    stack = []
    balanced = True
    pos = 0
    while pos < len(a_str) and balanced:
        symbol = a_str[pos]
        if symbol == '(':
            stack.append(symbol)
        elif symbol == ')':
            if not stack:
                balanced = False
                break
            else:
                stack.pop()
        else:
            pass
        pos += 1

    if balanced and not stack:
        return True
    else:
        return False


def _match_symbols(opener, closer):
    openers = '([{'
    closers = ')]}'
    match_bool = openers.index(opener) == closers.index(closer)
    return match_bool


def balance_symbols(a_str):
    """Balance "arbitrary" symbols in a string.
    The symbols here are '()', '[]' and '{}'. 
    """
    stack = []
    balanced = True
    pos = 0
    while pos < len(a_str) and balanced:
        symbol = a_str[pos]
        if symbol in '([{':
            stack.append(symbol)
        elif symbol in ')]}':
            if not stack:
                balanced = False
                break
            else:
                open_symbol = stack.pop()
                if not _match_symbols(open_symbol, symbol):
                    balanced = False
                    break
        else:
            pass
        pos += 1

    if balanced and not stack:
        return True
    else:
        return False


def main():
    import time

    text_match = '(abcd)'

    start_time = time.time()
    print('By balance_parentheses(): {}'
          .format(balance_parentheses(text_match)))
    print('Time: {}'.format(time.time() - start_time))

    start_time = time.time()
    print('By balance_symbols(): {}'
          .format(balance_symbols(text_match)))
    print('Time: {}'.format(time.time() - start_time))

    text_match2 = '([abcd]efg)'

    start_time = time.time()
    print('By balance_symbols(): {}'
          .format(balance_symbols(text_match2)))
    print('Time: {}'.format(time.time() - start_time))

    text_unmatch = '(abcd]'

    start_time = time.time()
    print('By balance_parentheses(): {}'
          .format(balance_parentheses(text_unmatch)))
    print('Time: {}'.format(time.time() - start_time))

    start_time = time.time()<commit_msg>Remove else: pass<commit_after>from __future__ import absolute_import
from __future__ import division
from __future__ import print_function


def balance_parentheses(a_str):
    """Balance parentheses in a string."""
    stack = []
    balanced = True
    pos = 0
    while pos < len(a_str) and balanced:
        symbol = a_str[pos]
        if symbol == '(':
            stack.append(symbol)
        elif symbol == ')':
            if not stack:
                balanced = False
                break
            else:
                stack.pop()
        pos += 1

    if balanced and not stack:
        return True
    else:
        return False


def _match_symbols(opener, closer):
    openers = '([{'
    closers = ')]}'
    match_bool = openers.index(opener) == closers.index(closer)
    return match_bool


def balance_symbols(a_str):
    """Balance "arbitrary" symbols in a string.
    The symbols here are '()', '[]' and '{}'. 
    """
    stack = []
    balanced = True
    pos = 0
    while pos < len(a_str) and balanced:
        symbol = a_str[pos]
        if symbol in '([{':
            stack.append(symbol)
        elif symbol in ')]}':
            if not stack:
                balanced = False
                break
            else:
                open_symbol = stack.pop()
                if not _match_symbols(open_symbol, symbol):
                    balanced = False
                    break
        pos += 1

    if balanced and not stack:
        return True
    else:
        return False


def main():
    import time

    text_match = '(abcd)'  # Ans: True.

    start_time = time.time()
    print('By balance_parentheses(): {}'
          .format(balance_parentheses(text_match)))
    print('Time: {}'.format(time.time() - start_time))

    start_time = time.time()
    print('By balance_symbols(): {}'
          .format(balance_symbols(text_match)))
    print('Time: {}'.format(time.time() - start_time))

    text_match2 = '([abcd]efg)'  # Ans: True.

    start_time = time.time()
    print('By balance_symbols(): {}'
          .format(balance_symbols(text_match2)))
    print('Time: {}'.format(time.time() - start_time))

    text_unmatch = '(abcd]'  # Ans: False.

    start_time = time.time()
    print('By balance_parentheses(): {}'
          .format(balance_parentheses(text_unmatch)))
    print('Time: {}'.format(time.time() - start_time))

    start_time = time.time()
{'fraction_non_alphanumeric': 0.12518134715025905, 'fraction_numerical': 0.002487046632124352, 'mean_word_length': 1.990086741016109, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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}}
{'dir': 'git-commits-cleaned', 'id': '316757', 'n_tokens_mistral': 1489, 'n_tokens_neox': 1415, 'n_words': 351}