Found 10476 Articles for Python

Program to Implement Queue in Python

AmitDiwan
Updated on 15-Apr-2021 13:43:53

1K+ Views

When it is required to implement a queue using Python, a queue class is created, and methods to add and delete elements are defined. An instance of the class is created, and these methods are called using the instance and relevant output is displayed.Below is a demonstration of the same −Example Live Democlass Queue_struct:    def __init__(self):       self.items = []    def check_empty(self):       return self.items == []    def enqueue_elem(self, data):       self.items.append(data)    def dequeue_elem(self):       return self.items.pop(0) my_instance = Queue_struct() while True:    print('Enqueue ') ... Read More

Python Program to Implement a Stack

AmitDiwan
Updated on 15-Apr-2021 13:43:28

4K+ Views

When it is required to implement a stack using Python, a stack class is created, and an instance of this class is created. Methods to push, pop elements are defined and the instance is used to call these methods.Below is a demonstration of the same −Example Live Democlass Stack_struct:    def __init__(self):       self.items = []    def check_empty(self):       return self.items == []    def add_elements(self, my_data):       self.items.append(my_data)    def delete_elements(self):       return self.items.pop() my_instance = Stack_struct() while True:    print('Push ')    print('Pop')    print('Quit')   ... Read More

How to use Boto3 to paginate through object versions of a S3 bucket present in AWS Glue

Ashish Anand
Updated on 15-Apr-2021 13:30:08

721 Views

Problem Statement: Use boto3 library in Python to paginate through object versions of a S3 bucket from AWS Glue Data Catalog that is created in your accountApproach/Algorithm to solve this problemStep 1: Import boto3 and botocore exceptions to handle exceptions.Step 2: max_items, page_size and starting_token are the optional parameters for this function, while bucket_name is required parameters.max_items denote the total number of records to return. If the number of available records > max_items then a NextToken will be provided in the response to resume pagination.page_size denotes the size of each page.starting_token helps to paginate, and it uses NextKeyMarker from a ... Read More

How to get the list of all versions of the object from S3 present in AWS Resource

Ashish Anand
Updated on 15-Apr-2021 13:29:48

3K+ Views

In this article, we will see how to get the list of all versions of the object from S3 those are present in AWS Resource.ExampleList out all the versions of test.zip from Bucket_1/testfolder of S3.Problem Statement: Use boto3 library in Python to get list of all versions of the object from S3.Approach/Algorithm to solve this problemStep 1: Import boto3 and botocore exceptions to handle exceptions.Step 2: bucket_name is the required parameter.Step 3: Create an AWS session using boto3 libStep 4: Create an AWS client for s3Step 5: Now, list out all version of the object of the given bucket using ... Read More

Python Program To Find the Smallest and Largest Elements in the Binary Search Tree

Farhan Muhamed
Updated on 19-Aug-2025 17:27:50

426 Views

In this article, we will explain how to find the minimum and maximum values in a binary search tree (BST), with implementation in Python. A binary search tree is a data structure that stores data in a sorted order such that for every node, the left subtree contains values less than the node's value, and the right subtree contains values greater than the node's value. So the leftmost node will have the minimum value, and the rightmost node will have the maximum value. Find Minimum and Maximum in a BST Given root node of a binary search tree, ... Read More

Python Program to Build Binary Tree if Inorder or Postorder Traversal as Input

AmitDiwan
Updated on 15-Apr-2021 13:35:40

418 Views

When it is required to build a binary tree by taking input using inorder or postorder traversal, a class is defined, that has methods to set the root element, perform inorder traversal, perform post order traversal. It can be used by creating an instance of the class.Below is a demonstration of the same −Example Live Democlass BinaryTree_struct:    def __init__(self, key=None):       self.key = key       self.left = None       self.right = None    def set_root(self, key):       self.key = key    def inorder_traversal(self):       if self.left is not ... Read More

How to use Boto3 to paginate through all triggers present in AWS Glue

Ashish Anand
Updated on 15-Apr-2021 13:27:48

218 Views

Problem Statement: Use boto3 library in Python to paginate through all triggers from AWS Glue Data Catalog that is created in your accountApproach/Algorithm to solve this problemStep 1: Import boto3 and botocore exceptions to handle exceptions.Step 2: max_items, page_size and starting_token are the optional parameters for this functionmax_items denote the total number of records to return. If the number of available records > max_items, then a NextToken will be provided in the response to resume pagination.page_size denotes the size of each page.starting_token helps to paginate, and it uses NextToken from a previous response.Step 3: Create an AWS session using boto3 ... Read More

Python Program to Find Nth Node in the Inorder Traversal of a Tree

AmitDiwan
Updated on 15-Apr-2021 13:35:21

240 Views

When it is required to find the ‘n’th node using inorder traversal of a binary tree, a binary tree class is created with methods to set the root element, add elements to left or right, perform in order traversal and so on. An instance of the class is created, and it can be used to access the methods.Below is a demonstration of the same −Example Live Democlass BinaryTree_struct:    def __init__(self, key=None):       self.key = key       self.left = None       self.right = None    def set_root(self, key):       self.key = key ... Read More

How to use Boto3 to paginate through all tables present in AWS Glue

Ashish Anand
Updated on 15-Apr-2021 13:26:06

833 Views

Problem Statement: Use boto3 library in Python to paginate through all tables from AWS Glue Data Catalog that is created in your accountApproach/Algorithm to solve this problemStep 1: Import boto3 and botocore exceptions to handle exceptions.Step 2: max_items, page_size and starting_token are the optional parameters for this function, while database_name is required.max_items denote the total number of records to return. If the number of available records > max_items, then a NextToken will be provided in the response to resume pagination.page_size denotes the size of each page.starting_token helps to paginate, and it uses NextToken from a previous response.Step 3: Create an ... Read More

Python Program to Convert a given Singly Linked List to a Circular List

AmitDiwan
Updated on 15-Apr-2021 13:34:59

369 Views

When it is required to convert a singly linked list into a circular linked list, a method named ‘convert_to_circular_list’ is defined that ensures that the last elements points to the first element, thereby making it circular in nature.Below is a demonstration of the same −Example Live Democlass Node:    def __init__(self, data):       self.data = data       self.next = None class LinkedList_struct:    def __init__(self):       self.head = None       self.last_node = None    def add_elements(self, data):       if self.last_node is None:          self.head = Node(data) ... Read More

Advertisements