How to use __start method in ATX

Best Python code snippet using ATX

circular_linked_list.py

Source:circular_linked_list.py Github

copy

Full Screen

1class Node:2 def __init__(self, element) -> None:3 self.data = element4 self.next = None5class CircularLinkedList:6 def __init__(self) -> None:7 self.__start = None8 self.__tail = None9 10 def insert_node_at_beginning(self, element):11 node = Node(element)12 if self.__start is None:13 node.next = node14 self.__tail = node15 else:16 node.next = self.__start17 self.__start = node18 self.__tail.next = self.__start19 def insert_node_at_end(self, element):20 node = Node(element)21 if self.__tail:22 self.__tail.next = node23 self.__tail = node24 node.next = self.__start25 def insert_node_at_index(self, element, index):26 node = Node(element)27 temp = self.__start28 for i in range(0, index-1):29 if temp.next:30 temp = temp.next31 else:32 raise RuntimeError("Invalid index")33 node.next = temp.next34 temp.next = node35 def delete_node_at_beginning(self):36 if self.__start is None:37 return 38 self.__start = self.__start.next39 self.__tail.next = self.__start40 def delete_node_at_end(self):41 if self.__tail is None:42 return43 temp = self.__start44 while temp.next != self.__tail:45 temp = temp.next46 self.__tail = temp47 temp.next = self.__start48 def delete_node_at_index(self, index):49 temp = self.__start50 for i in range(0, index-1):51 if temp.next:52 temp = temp.next53 else:54 raise RuntimeError("Invalid index")55 temp.next = temp.next.next56 def size(self):57 len = 058 temp = self.__start59 if not temp:60 return len61 len = 162 temp = temp.next63 while temp and temp != self.__start:64 len += 165 temp = temp.next66 return len67 def display(self):68 temp = self.__start69 if not temp:70 return71 print(temp.data, end=' ')72 temp = temp.next73 while temp and temp != self.__start:74 print(temp.data, end=' ')75 temp = temp.next76 print()77if __name__ == '__main__':78 circular_linked_list = CircularLinkedList()79 circular_linked_list.insert_node_at_beginning(1)80 circular_linked_list.insert_node_at_beginning(2)81 circular_linked_list.insert_node_at_beginning(3)82 circular_linked_list.insert_node_at_end(4)83 circular_linked_list.insert_node_at_end(5)84 circular_linked_list.insert_node_at_end(6)85 circular_linked_list.insert_node_at_index(11, 3)86 circular_linked_list.insert_node_at_index(15, 6)87 circular_linked_list.insert_node_at_index(19, 3)88 circular_linked_list.display()89 print("Size of list is " + str(circular_linked_list.size()))90 circular_linked_list.delete_node_at_beginning()91 circular_linked_list.delete_node_at_end()92 circular_linked_list.delete_node_at_index(3)93 circular_linked_list.display()...

Full Screen

Full Screen

coordinates.py

Source:coordinates.py Github

copy

Full Screen

1from dataclasses import dataclass2@dataclass(eq=True, frozen=True)3class Coord:4 x: int5 y: int6 z: int = None7 def __repr__(self):8 if (self.z):9 return f'[{self.x}:{self.y}:{self.z}]'10 else:11 return f'[{self.x}:{self.y}]'12 def rotate(self, angle=0):13 (x, y) = [14 (self.x, self.y),15 (self.y, -self.x),16 (-self.x, -self.y),17 (-self.y, self.x)18 ][angle]19 return Coord(x, y)20class DeltaCoord(Coord):21 def __repr__(self):22 fmt = '{:+d}'23 if (self.z):24 return f'({fmt.format(self.x)}:{fmt.format(self.y)}:{fmt.format(self.z)})'25 else:26 return f'({fmt.format(self.x)}:{fmt.format(self.y)})'27class Move(object):28 def __init__(self, direction: DeltaCoord = None, start: Coord = None,29 destination: Coord = None):30 self.__destination = destination31 self.__start = start32 self.__direction = direction33 self.__checkValues()34 def setStart(self, start: Coord = None):35 self.__start = start36 self.__checkValues()37 def setDirection(self, direction: DeltaCoord = None):38 self.__direction = direction39 if (self.__start):40 self.__destination = Coord(41 self.__start.x + self.__direction.x,42 self.__start.y + self.__direction.y,43 (self.__start.z or 0) + (self.__direction.z or 0)44 )45 def getDestination(self): return self.__destination46 def setDestination(self, destination: Coord = None):47 self.__destination = destination48 if (self.__start):49 self.__direction = Coord(50 self.__destination.x - self.__start.x,51 self.__destination.y - self.__start.y,52 (self.__destination.z or 0) - (self.__start.z or 0)53 )54 destination = property(getDestination, setDestination)55 def __checkValues(self):56 if (self.__start):57 if (self.__direction):58 self.__destination = Coord(59 self.__start.x + self.__direction.x,60 self.__start.y + self.__direction.y,61 (self.__start.z or 0) + (self.__direction.z or 0)62 )63 elif (self.__destination):64 self.__direction = Coord(65 self.__destination.x - self.__start.x,66 self.__destination.y - self.__start.y,67 (self.__destination.z or 0) - (self.__start.z or 0)68 )69 def __repr__(self):70 if (self.__start):71 return f"<{self.__class__.__name__} {self.__start}->{self.__destination}>"...

Full Screen

Full Screen

timeutil.py

Source:timeutil.py Github

copy

Full Screen

1#!/usr/bin/python2#coding:utf83import time4class StopWatch(object):5 def __init__(self):6 self.reset()7 def reset(self):8 self.__start = 0.09 self.__second = 0.010 def go(self):11 if self.__start == 0.0:12 self.__start = time.time()13 def reset_go(self):14 self.reset()15 self.go()16 def pause(self):17 if self.__start != 0.0:18 now = time.time()19 self.__second = (now - self.__start)20 self.__start = 0.021 def get(self):22 '''return millsecond (毫秒)'''23 second = self.__second24 if self.__start != 0.0:25 now = time.time()26 second += (now - self.__start)27 return second * 100028def main():29 watch = StopWatch()30 watch.go()31 print watch.get()32 time.sleep(1.5)33 print watch.get()34 time.sleep(1.5)35 print watch.get()36 watch.pause()37 time.sleep(1.5)38 print watch.get()39if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ATX automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful