Skip to content

Commit 0b06cc8

Browse files
committed
.sort() method
1 parent 07e7e5c commit 0b06cc8

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

main.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,7 @@ def __add__(self, other: Any) -> "Table":
187187
return Table(self.list, self.dict | other)
188188
else:
189189
raise TypeError(f"unsupported operand type(s) for +: 'Table' and '{type(other).__name__}'")
190-
190+
@override
191+
def sort(self, key: Optional[Callable]=None, reverse: bool=False):
192+
self.list.sort(key=key, reverse=reverse)
193+
return self

tests/test_main.py

+1
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ def test_tables():
3636
assert x == Table(1,2,3, foo="bar", spam="eggs"), "Test 7 failed!"
3737
assert x + Table(4,5,6) == Table(1,2,3,4,5,6, foo="bar", spam="eggs"), "Test 8 failed!"
3838
assert x.foreach(lambda k, v: [k, v]) == [0, 1, 1, 2, 2, 3, "foo", "bar", "spam", "eggs"], "Test 9 failed!"
39+
assert Table(1,3,2).sort() == Table(1,2,3), "Test 10 failed!"
3940
#congrats, the code works!
4041
print("All tests passed!")

0 commit comments

Comments
 (0)