got distracted and made a repl framework.......

This commit is contained in:
Emile Clark-Boman 2025-06-22 00:26:54 +10:00
parent 0a2d9a5694
commit c18aa29c58
5 changed files with 227 additions and 17 deletions

View file

@ -15,3 +15,14 @@ Left pad an integer's binary representation with zeros
def lpadbin(x: int, n: int) -> str:
return lpad(bin(x)[2:], n, pad='0')
'''
Extends the standard lstrip string method,
allowing the max: int kwarg to be supplied.
'''
def lstrip(s: str, prefix: str, max: int = -1) -> str:
l = len(prefix)
c = 0
while s.startswith(prefix) and c < max:
s = s[l:]
c += 1
return s

8
bcrypter/lib/other.py Normal file
View file

@ -0,0 +1,8 @@
'''
Implements a safe way of indexing a list.
'''
def tryget(L: list[Any], i: int, default: Any | None = None) -> Any:
try:
return L[i]
except IndexError:
return default