Skip to content

Commit

Permalink
a bit of cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Mego committed Jun 13, 2024
1 parent 885299a commit 5c21ef2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
3 changes: 1 addition & 2 deletions seriously/SeriouslyCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

import operator, cmath
import math as rmath
import random, itertools, sys, string, binascii, ast
import random, itertools, sys, string, ast
from base64 import *
from copy import deepcopy as _copy
import collections
from functools import reduce, lru_cache
import struct
import types
from itertools import zip_longest as izip
from seriouslylib.cp437 import CP437
from seriouslylib.iterable import deque, as_list, zip_longest
Expand Down
19 changes: 11 additions & 8 deletions seriouslylib/iterable.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
#!/usr/bin/env python3

from collections import deque as _deque
from collections import Iterable
from itertools import islice, zip_longest as izip
from collections.abc import Iterable
from itertools import zip_longest as izip


def as_list(val, wrap=True):
#strings are iterables all the way down, so an exception needs to be made
# strings are iterables all the way down, so an exception needs to be made
# else we get infinite recursion, which is bad
# this only took me 2 hours to debug, new record!
if not isinstance(val, Iterable) or isinstance(val, str):
return [val] if wrap else val
else:
return [as_list(x, wrap=False) for x in val]



class deque(_deque):
def copy(self):
if hasattr(_deque, 'copy'):
if hasattr(_deque, "copy"):
return _deque.copy(self)
else:
return deque(x for x in self)

def __getitem__(self, key):
if isinstance(key, slice):
return [x for x in self][key]
else:
return _deque.__getitem__(self, key)

def reversed(self):
tmp = self.copy()
tmp.reverse()
return tmp


def zip_longest(*iterables):
for vals in izip(*iterables):
yield filter(lambda x:x is not None, vals)
yield filter(lambda x: x is not None, vals)

0 comments on commit 5c21ef2

Please sign in to comment.