Skip to content

Instantly share code, notes, and snippets.

View HETHAT's full-sized avatar
🇵🇸

HETHAT Mohamed HETHAT

🇵🇸
  • Algeria
View GitHub Profile
@HETHAT
HETHAT / 1_liner_linked_list.py
Last active April 11, 2022 22:53
just a normal one liner linked list
Node = type("Node",(),{'__init__': lambda self, data, _next=None: setattr(self, "data", data) or setattr(self, "next", _next),'__repr__': lambda self: f"Node<{self.data.__repr__()}>",'__gt__': lambda self, other: self.data > other.data if other.__class__ == Node else self.data > other});LinkedList = type("LinkedList",(),{'__init__': lambda self, data=None:setattr(self, "head", None) or setattr(self, "last", None)or setattr(self, "len", 0) or data is not None and self.extend(data) or None,'_ci': lambda self, index: index if index >= 0 else self.len + index,'append': lambda self, obj:(last := Node(obj))and (self.head is not None or not setattr(self, "head", last))and (self.last is None or not setattr(self.last, "next", last))and not setattr(self, "last", last) and setattr(self, "len", self.len + 1),'index': lambda self, obj, start=0, stop=None:(stop := self.len if stop is None else stop) * 0 or(start := self._ci(start), stop := self._ci(stop)) and( __loop := lambda index, item:None if item is None or index >= s