<commit_before>import re
import collections
try:
    from urllib import quote_plus
except ImportError:
    from urllib.parse import quote_plus


def to_params(hash):
    normalized = map(lambda (k, v): normalize_param(k, v), hash.iteritems())
    return dict((k, v) for d in normalized for (k, v) in d.items())


def normalize_param(key, value):
    """Convert a set of key, value parameters into a dictionary suitable for
    passing into requests. This will convert lists into the syntax required
    by SoundCloud. Heavily lifted from HTTParty.

    >>> normalize_param('playlist', {
    ...  'title': 'foo',
    ...  'sharing': 'private',
    ...  'tracks': [
    ...    {id: 1234}, {id: 4567}
    ...  ]})  # doctest:+ELLIPSIS
    {u'playlist[tracks][][<built-in function id>]': [1234, 4567], u'playlist[sharing]': 'private', u'playlist[title]': 'foo'}

    >>> normalize_param('oauth_token', 'foo')
    {'oauth_token': 'foo'}

    >>> normalize_param('playlist[tracks]', [1234, 4567])
    {u'playlist[tracks][]': [1234, 4567]}
    """
    params = {}
    stack = []
    if isinstance(value, list):
        normalized = map(lambda e: normalize_param(u"{0[key]}[]".format(dict(key=key)), e), value)
        keys = [item for sublist in tuple(h.keys() for h in normalized) for item in sublist]

        lists = {}
        if len(keys) != len(set(keys)):
            duplicates = [x for x, y in collections.Counter(keys).items() if y > 1]
            for dup in duplicates:
                lists[dup] = [h[dup] for h in normalized]<commit_msg>Convert map lambda to list comprehension.<commit_after>import re
import collections
try:
    from urllib import quote_plus
except ImportError:
    from urllib.parse import quote_plus


def to_params(hash):
    normalized = [normalize_param(k, v) for (k, v) in hash.iteritems()]
    return dict((k, v) for d in normalized for (k, v) in d.items())


def normalize_param(key, value):
    """Convert a set of key, value parameters into a dictionary suitable for
    passing into requests. This will convert lists into the syntax required
    by SoundCloud. Heavily lifted from HTTParty.

    >>> normalize_param('playlist', {
    ...  'title': 'foo',
    ...  'sharing': 'private',
    ...  'tracks': [
    ...    {id: 1234}, {id: 4567}
    ...  ]})  # doctest:+ELLIPSIS
    {u'playlist[tracks][][<built-in function id>]': [1234, 4567], u'playlist[sharing]': 'private', u'playlist[title]': 'foo'}

    >>> normalize_param('oauth_token', 'foo')
    {'oauth_token': 'foo'}

    >>> normalize_param('playlist[tracks]', [1234, 4567])
    {u'playlist[tracks][]': [1234, 4567]}
    """
    params = {}
    stack = []
    if isinstance(value, list):
        normalized = [normalize_param(u"{0[key]}[]".format(dict(key=key)), e) for e in value]
        keys = [item for sublist in tuple(h.keys() for h in normalized) for item in sublist]

        lists = {}
        if len(keys) != len(set(keys)):
            duplicates = [x for x, y in collections.Counter(keys).items() if y > 1]
            for dup in duplicates:
                lists[dup] = [h[dup] for h in normalized]
{'fraction_non_alphanumeric': 0.1574372182871861, 'fraction_numerical': 0.02189311010946555, 'mean_word_length': 3.104359313077939, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '5499557', 'n_tokens_mistral': 1079, 'n_tokens_neox': 998, 'n_words': 300}