Skip to content

Instantly share code, notes, and snippets.

@luqmana
Created July 28, 2022 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luqmana/266c961101a86e57007e694fc27ba5d0 to your computer and use it in GitHub Desktop.
Save luqmana/266c961101a86e57007e694fc27ba5d0 to your computer and use it in GitHub Desktop.
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