<commit_before>#!/usr/bin/env python

from itertools import izip_longest
from operator import mul as multiply
from math import log
from pydigree.cyfuncs import runs, runs_gte, spans, interleave
from pydigree.cyfuncs import all_same_type


def count(val, iter):
    """ Counts how many times a value (val) occurs in an iterable """
    return sum(1 for x in (y for y in iter if y is not None) if val == x)


def table(seq):
    """
    For each unique value in seq, runs count() on it. Returns a dictionary in
    the form of {value1: count, value2: count}.
    """
    seq = [x for x in seq]
    keys = set(seq)
    return dict([(k, seq.count(k)) for k in keys])


def flatten(x):
    """
    Recursively flattens lists.
    From:
    stackoverflow.com/questions/5409224/python-recursively-flatten-a-list
    """
    try:<commit_msg>numpy random choice doesnt play well with iterables of iterables<commit_after>#!/usr/bin/env python
import numpy as np
from itertools import izip_longest
from operator import mul as multiply
from math import log
from pydigree.cyfuncs import runs, runs_gte, spans, interleave
from pydigree.cyfuncs import all_same_type


def count(val, iter):
    """ Counts how many times a value (val) occurs in an iterable """
    return sum(1 for x in (y for y in iter if y is not None) if val == x)


def table(seq):
    """
    For each unique value in seq, runs count() on it. Returns a dictionary in
    the form of {value1: count, value2: count}.
    """
    seq = [x for x in seq]
    keys = set(seq)
    return dict([(k, seq.count(k)) for k in keys])

def random_choice(iterable):
    itersize = len(iterable)
    randidx = np.random.randint(0, itersize)
    return iterable[randidx]

def flatten(x):
    """
    Recursively flattens lists.
    From:
    stackoverflow.com/questions/5409224/python-recursively-flatten-a-list
    """
    try:
{'fraction_non_alphanumeric': 0.09962506695232994, 'fraction_numerical': 0.011247991430101767, 'mean_word_length': 3.324074074074074, 'pattern_counts': {'":': 0, '<': 3, '<?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': '306432', 'n_tokens_mistral': 637, 'n_tokens_neox': 604, 'n_words': 231}