<commit_before>import itertools
import random

from math import factorial
from permutation import Permutation


class Permutations(itertools.permutations):
    """Class for iterating through all Permutations of a specific length."""

    def __new__(cls, length):
        domain = tuple(range(1, length+1))
        instance = super(Permutations, cls).__new__(cls, domain)
        return instance

    def __init__(self, length):
        self.length = length

    def next(self):
        return Permutation(super(Permutations, self).next())

    def random_element(self):
        """Return a random permutation of the length."""
        lst = list(range(1, self.length+1))
        random.shuffle(lst)
        return Permutation(lst)

    def __len__(self):
        return factorial(self.length)

    def __str__(self):
        return "The set of Permutations of length {}".format(self.length)

    def __repr__(self):
        return "Permutations({})".format(self.length)<commit_msg>Still having errors in Python 3 due to iter working differently (I believe)<commit_after>import itertools
import random

from math import factorial
from permuta import Permutation


class Permutations(itertools.permutations):
    """Class for iterating through all Permutations of a specific length."""

    __slots__ = ("length", "domain")

    def __new__(cls, length):
        domain = list(range(1, length+1))  # TODO: xrange or future
        instance = super(Permutations, cls).__new__(cls, domain)
        instance.domain = domain
        instance.length = length
        return instance

    def next(self):
        return Permutation(super(Permutations, self).next())

    def __iter__(self):
        return self

    def random_element(self):
        """Return a random permutation of the length."""
        lst = self.domain[:]
        random.shuffle(lst)
        return Permutation(lst)

    def __len__(self):
        return factorial(self.length)

    def __str__(self):
        return "The set of Permutations of length {}".format(self.length)

    def __repr__(self):
        return "Permutations({})".format(self.length)
{'fraction_non_alphanumeric': 0.1019348749410099, 'fraction_numerical': 0.0033034450212364322, 'mean_word_length': 3.124513618677043, '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': '7114260', 'n_tokens_mistral': 611, 'n_tokens_neox': 568, 'n_words': 178}