Skip to content

Commit 77f5b18

Browse files
committed
logics-py: Implementing keys() and values()
1 parent 44595ff commit 77f5b18

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

logics-py/logics/logics.py

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def __init__(self, src: str, debug: bool = False):
3939
"float": parse_float,
4040
"int": parse_int,
4141
"join": lambda value, delimiter=", ": str(delimiter).join(str(item) for item in value.list()),
42+
"keys": lambda obj: list(obj.dict().keys()),
4243
"len": len,
4344
"lfill": lambda value, length, fill=" ": str(value).rjust(int(length), str(fill)),
4445
"lower": lambda value: str(value).lower(),
@@ -55,6 +56,7 @@ def __init__(self, src: str, debug: bool = False):
5556
"strip": lambda s, c=" \t\r\n": str(s).strip(str(c)),
5657
"sum": lambda value: sum([Value.align(item, allow=(bool, int, float), default=0) for item in value]),
5758
"upper": lambda value: str(value).upper(),
59+
"values": lambda obj: list(obj.dict().values()),
5860
}
5961

6062
self.debug = debug

logics-py/logics/value.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ def type(self):
157157

158158
return name
159159

160+
def __hash__(self):
161+
return hash(self.value)
162+
160163
def __repr__(self):
161164
if self.type() == "str":
162165
return '"' + re.sub(r"([\"\\])", r"\\\1", self.value) + '"'
@@ -195,7 +198,7 @@ def dict(self) -> dict:
195198
if self.type() == "dict":
196199
return self.value
197200

198-
return {self.value: self.value}
201+
return {i: i for i in self.list()}
199202

200203
def __len__(self):
201204
if self.type() in ("dict", "list", "str"):

0 commit comments

Comments
 (0)