Skip to content

Nice little tool #3

Description

@sfinktah

This, a bit of regex, and a few previously created shims did the trick for a tiny bit of code.

Thought I would include those shims for other people. They are quick and nasty :)

from collections import defaultdict

def array(*args):
    return defaultdict(array)
def array_keys(a):
    if isinstance(a, list):
        return range(len(a))
    return a.keys()
def array_shift(a):
    return a.pop(0)
def foreach(a):
    if isinstance(a, list):
        return enumerate(a)
    return a.items()
def explode(by, s):
    return s.split(by)
def implode(by, a):
    if isinstance(a, list):
        return by.join(a)
    raise TypeError('Not a list')
def count(a):
    return len(a)
def strlen(a):
    return len(a)
def array_reverse(array):
    copy = array[:]
    copy.reverse()
    return copy
def ucfirst(s):
    if len(s) > 1:
        return s[0].upper() + s[1:]
    if len(s):
        return s[0].upper()
    return s

STDOUT = STDERR = 0
def fprintf(dst, fmt, *args):
    print(fmt, *args)

false = False
true = True

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions