Created
July 28, 2022 19:44
-
-
Save luqmana/266c961101a86e57007e694fc27ba5d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import builtins | |
import math | |
class BetterList(builtins.list): | |
def __getitem__(self, k): | |
if isinstance(k, slice): | |
if k.start == None and k.step == None: | |
if k.stop == 0.0: | |
if math.copysign(1.0, k.stop) == -1.0: | |
return self | |
else: | |
return super().__getitem__(slice(None, 0, None)) | |
return super().__getitem__(k) | |
builtins.list = BetterList | |
fruit = list('πππ') | |
print(fruit[:0.0]) # [] | |
print(fruit[:-0.0]) # ['π', 'π', 'π'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment