def all(iterable): for i in iterable: if not i: return False return True def any(iterable): for i in iterable: if i: return True return False def enumerate(iterable, start=0): n = start for elem in iterable: yield n, elem n += 1 def __minmax_reduce(op, args): if len(args) == 2: # min(1, 2) return args[0] if op(args[0], args[1]) else args[1] if len(args) == 0: # min() raise TypeError('expected 1 arguments, got 0') if len(args) == 1: # min([1, 2, 3, 4]) -> min(1, 2, 3, 4) args = args[0] args = iter(args) try: res = next(args) except StopIteration: raise ValueError('args is an empty sequence') while True: try: i = next(args) except StopIteration: break if op(i, res): res = i return res def min(*args, key=None): key = key or (lambda x: x) return __minmax_reduce(lambda x,y: key(x)key(y), args) def sum(iterable): res = 0 for i in iterable: res += i return res def map(f, iterable): for i in iterable: yield f(i) def filter(f, iterable): for i in iterable: if f(i): yield i def zip(a, b): a = iter(a) b = iter(b) while True: try: ai = next(a) bi = next(b) except StopIteration: break yield ai, bi def reversed(iterable): a = list(iterable) a.reverse() return a def sorted(iterable, key=None, reverse=False): a = list(iterable) a.sort(key=key, reverse=reverse) return a def dir(obj=None): """ dir([object]) -> list of strings If called without an argument, return the names in the current scope. Else, return an alphabetized list of names comprising (some of) the attributes of the given object, and of attributes reachable from it. If the object supplies a method named __dir__, it will be used; otherwise the default dir() logic is used and returns: for a module object: the module's attributes. for a class object: its attributes. for any other object: its attributes, its class's attributes. """ if obj is None: return list(globals().keys()) if hasattr(obj, "__dir__"): return obj.__dir__ attributes = set() # Set object attributes. if hasattr(obj, "__dict__"): attributes.update(obj.__dict__.keys()) # Set type attributes. if not isinstance(obj, type): if hasattr(type(obj), "__dict__"): attributes.update(type(obj).__dict__.keys()) return sorted(attributes) ##### str ##### def __format_string(self: str, *args, **kwargs) -> str: def tokenizeString(s: str): tokens = [] L, R = 0,0 mode = None curArg = 0 # lookingForKword = False while(R