Skip to content

Commit 73344d1

Browse files
authored
Merge pull request #8 from danielenricocahall/add-negative-indexing
Add negative slicing support
2 parents bcba0a5 + e59516c commit 73344d1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

superstring/superstring.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ def __str__(self):
7373
return self.toPrintable()
7474

7575
def __getitem__(self, key):
76-
# TODO: Negative Indexing
7776
if isinstance(key, slice):
78-
return self.substring(key.start, endIndex = key.stop)
77+
start = key.start if key.start > 0 else self.length() + key.start
78+
stop = key.stop if key.stop > 0 else self.length() + key.stop
79+
return self.substring(start, end_index=stop)
7980
return self.characterAt(key)
8081

8182
class SuperString(SuperStringBase):

0 commit comments

Comments
 (0)