Found 10476 Articles for Python

Python Program to Count Number of Leaf Node in a Tree

AmitDiwan
Updated on 15-Apr-2021 12:53:11

632 Views

When it is required to count the number of leaf nodes in a Tree, a ‘Tree_structure’ class is created, methods to add root value, and other children values are defined. Various options are given that the user can select. Based on the user’s choice, the operation is performed on the Tree elements.Below is a demonstration of the same −Example Live Democlass Tree_structure:    def __init__(self, data=None):       self.key = data       self.children = []    def set_root_node(self, data):       self.key = data    def add_vals(self, node):       self.children.append(node)    def ... Read More

How to use Boto3 to get the list of triggers present in an AWS account

Ashish Anand
Updated on 15-Apr-2021 12:50:22

459 Views

In this article, we will see how a user can get the list of all triggers present in an AWS account.ExampleGet the list of all triggers available in an AWS Glue Data Catalog.Problem Statement: Use boto3 library in Python to get the list of all triggers.Approach/Algorithm to solve this problemStep 1: Import boto3 and botocore exceptions to handle exceptions.Step 2: There are no parameters in this function.Step 3: Create an AWS session using boto3 lib. Make sure region_name is mentioned in default profile. If it is not mentioned, then explicitly pass the region_name while creating the session.Step 4: Create an ... Read More

How to use Boto3 to get the list of schemas present in AWS account

Ashish Anand
Updated on 15-Apr-2021 12:50:01

379 Views

In this article, we will see how a user can get the list of all schemas present in an AWS account.ExampleGet the list of all the schemas available in an AWS Glue Data Catalog.Problem Statement: Use boto3 library in Python to get the list of all schemas.Approach/Algorithm to solve this problemStep 1: Import boto3 and botocore exceptions to handle exceptions.Step 2: There are no parameters in this function.Step 3: Create an AWS session using boto3 lib. Make sure region_name is mentioned in default profile. If it is not mentioned, then explicitly pass the region_name while creating the session.Step 4: Create ... Read More

How to get the list of all registries present in an AWS account using Boto3

Ashish Anand
Updated on 15-Apr-2021 12:49:42

151 Views

In this article, we will see how a user can get the list of all registries present in an AWS account.ExampleGet the list of all registries available in AWS Glue Data Catalog.Problem Statement: Use boto3 library in Python to get the list of all registries.Approach/Algorithm to solve this problemStep 1: Import boto3 and botocore exceptions to handle exceptions.Step 2: There are no parameters in this function.Step 3: Create an AWS session using boto3 lib. Make sure region_name is mentioned in the default profile. If it is not mentioned, then explicitly pass the region_name while creating the session.Step 4: Create an ... Read More

How to get the list of all crawlers present in an AWS account using Boto3

Ashish Anand
Updated on 15-Apr-2021 12:49:20

481 Views

In this article, we will see how a user can get the list of all crawlers present in an AWS account.ExampleProblem Statement: Use boto3 library in Python to get the list of all crawlers.Approach/Algorithm to solve this problemStep 1: Import boto3 and botocore exceptions to handle exceptions.Step 2: There are no parameters in this function.Step 3: Create an AWS session using boto3 lib. Make sure region_name is mentioned in the default profile. If it is not mentioned, then explicitly pass the region_name while creating the session.Step 4: Create an AWS client for glue.Step 5: Now use the list_crawlersStep 6: It ... Read More

How to get the details of a workflow using Boto3

Ashish Anand
Updated on 15-Apr-2021 12:49:03

361 Views

In this article, we will see how a user can get the resource metadata of a workflow.ExampleGet the details of a workflow from AWS Glue Data Catalog that is created in your account.Problem Statement: Use boto3 library in Python to get the metadata of a workflow that is created in your account.Approach/Algorithm to solve this problemStep 1: Import boto3 and botocore exceptions to handle exceptions.Step 2: workflow_name is the required parameter for this function. It will fetch the metadata of the given workflow.Step 3: Create an AWS session using boto3 lib. Make sure region_name is mentioned in the default profile. ... Read More

Python Program to Implement Queues using Stacks

AmitDiwan
Updated on 15-Apr-2021 12:46:57

383 Views

When it is required to implement a queue using a stack, a queue class can be defined, where two stack instances can be defined. Different operations can be performed on the queue that are defined as methods in this class.Below is a demonstration of the same −Example Live Democlass Queue_structure:    def __init__(self):       self.in_val = Stack_structure()       self.out_val = Stack_structure()    def check_empty(self):       return (self.in_val.check_empty() and self.out_val.check_empty())    def enqueue_operation(self, data):       self.in_val.push_operation(data)    def dequeue_operation(self):       if self.out_val.check_empty():          while not self.in_val.check_empty(): ... Read More

Python Program to Implement Stack Using Two Queues

AmitDiwan
Updated on 15-Apr-2021 12:45:01

574 Views

When it is required to implement a stack using two queues, a ‘Stack_structure’ class is required along with a Queue_structure class. Respective methods are defined in these classes to add and delete values from the stack and queue respectively.Below is a demonstration of the same −Example Live Democlass Stack_structure:    def __init__(self):       self.queue_1 = Queue_structure()       self.queue_2 = Queue_structure()    def check_empty(self):       return self.queue_2.check_empty()    def push_val(self, data):       self.queue_1.enqueue_operation(data)       while not self.queue_2.check_empty():          x = self.queue_2.dequeue_operation()          self.queue_1.enqueue_operation(x)   ... Read More

Python Program to Implement Stack using One Queue

AmitDiwan
Updated on 15-Apr-2021 12:43:52

820 Views

When it is required to implement a stack using a single queue, a ‘Stack_structure’ class is required along with a Queue_structure class. Respective methods are defined in these classes to add and delete values from the stack and queue respectively.Below is a demonstration of the same −Example Live Democlass Stack_structure:    def __init__(self):       self.q = Queue_structure()    def check_empty(self):       return self.q.check_empty()    def push_val(self, data):       self.q.enqueue_operation(data)    def pop_val(self):       for _ in range(self.q.size_calculate() - 1):          dequeued = self.q.dequeue_operation()         ... Read More

Python Program to Reverse a Stack using Recursion

AmitDiwan
Updated on 15-Apr-2021 12:44:34

661 Views

When it is required to reverse a stack data structure using recursion, a ‘stack_reverse’ method, in addition to methods to add value, delete value, and print the elements of the stack are defined.Below is a demonstration of the same −Example Live Democlass Stack_structure:    def __init__(self):       self.items = []    def check_empty(self):       return self.items == []    def push_val(self, data):       self.items.append(data)    def pop_val(self):       return self.items.pop()    def print_it(self):       for data in reversed(self.items):          print(data) def insert_bottom(instance, data): ... Read More

Advertisements