Best Python code snippet using tempest_python
datatypes.py
Source:datatypes.py  
1import copy2class Childs():3  class Node():4    def __init__(self, container=None):5      self.container = container6      self._prev = None7      self._next = None8  def __init__(self, *iterable):9    self._head = Childs.Node()10    self._head._prev = self._head11    self._head._next = self._head12    self._len = 013  def __len__(self):14    return self._len15  def append(self, container=None):16    new_node = Childs.Node(container)17    new_node._prev = self._head18    new_node._next = self._head._next19    self._head._next._prev = new_node20    self._head._next = new_node21    self._len += 122    return new_node23  def delete(self, node):24    node._prev._next = node._next25    node._next._prev = node._prev26    self._len -= 127  def move_top(self, node):28    node._prev._next = node._next29    node._next._prev = node._prev30    node._prev = self._head31    node._next = self._head._next32    self._head._next._prev = node33    self._head._next = node34    35  def printall(self):36    n = self._head._next37    i=038    while not n == self._head:39      print(n.container)40      n = n._next41      i += 142      if i == self._len : break43  def __iter__(self):44    return Childs.Iterator(self)45  def __reversed__(self):46    return Childs.ReversedIterator(self)47  class Iterator():48    def __init__(self, childs):49      self._childs = childs50      self._next_node = self._childs._head51    def __iter__(self):52      return self53    def __next__(self):54      self._next_node = self._next_node._next55      if not self._next_node == self._childs._head:56        return self._next_node57      else:58        raise StopIteration59  class ReversedIterator(Iterator):60    def __init__(self, childs):61      super().__init__(childs)62    63    def __next__(self):64      self._next_node = self._next_node._prev65      if not self._next_node == self._childs._head:66        return self._next_node67      else:68        raise StopIteration69    ...100-singly_linked_list.py
Source:100-singly_linked_list.py  
1#!/usr/bin/python32"""create a linked list using classes"""3class Node:4    """create a node"""5    def __init__(self, data, next_node=None):6        self._data = data7        self._next_node = next_node8    @property9    def data(self):10        """getter of the data"""11        return self._data12    @data.setter13    def data(self, value):14        """setter of the data"""15        if type(value) != int:16            raise TypeError("data must be an integer")17        self._data = value18    @property19    def next_node(self):20        """getter of the data"""21        return self._next_node22    @next_node.setter23    def next_node(self, value):24        """setter of the next_node"""25        if value is not None or value is not Node():26            raise TypeError("next_node must be a Node object")27        self._next_node = value28class SinglyLinkedList:29    """create a new linked list"""30    def __init__(self):31        """create a linked list"""32        self.__head = None33    def sorted_insert(self, value):34        """insert a new node"""35        new_node = Node(value)36        if self.__head is None:37            self.__head = new_node38        elif value < self.__head._data:39            new_node._next_node = self.__head40            self.__head = new_node41        else:42            temp = self.__head43            while temp._next_node and temp._next_node._data < value:44                temp = temp._next_node45            new_node._next_node = temp._next_node46            temp._next_node = new_node47    def __str__(self):48        """make the list printable"""49        temp = self.__head50        linked_list = ""51        while temp:52            if temp.next_node is None:53                linked_list += str(temp._data)54            else:55                linked_list += str(temp._data) + "\n"56            temp = temp._next_node...iter4.py
Source:iter4.py  
1class List:2    class _Node:3        __slots__ = ('value', 'next')4        5        def __init__(self, value, next=None):6            self.value = value7            self.next = next8    class _NodeIterator:9        def __init__(self, first):10            self._next_node = first11        def __iter__(self):12            return self13        def __next__(self):14            if self._next_node is None:15                raise StopIteration16            value = self._next_node.value17            self._next_node = self._next_node.next18            return value19    def __init__(self, iterable=None):20        self._head = None21        self._tail = None22        self._length = 023        if iterable is not None:24            self.extend(iterable)25    def __len__(self):26        return self._length27    def append(self, value):28        node = List._Node(value)29        if len(self) == 0:30            self._head = self._tail = node31        else:32            self._tail.next = node33            self._tail = node34        self._length += 135    def extend(self, iterable):36        for value in iterable:37            self.append(value)38    def __getitem__(self, index):39        if index < 0:40            index += len(self)41        if not 0 <= index < len(self):42            raise IndexError('list index out of range')43        node = self._head44        for _ in range(index):45            node = node.next46        return node.value47    def __iter__(self):48        return List._NodeIterator(self._head)49if __name__ == '__main__':50    numbers = List(range(100000))51    for x in numbers:52        if x % 1000 == 0:...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
