Python program to unique keys count for Value in Tuple List

AmitDiwan
Updated on 25-Mar-2026 18:45:48

219 Views

When working with lists of tuples, you may need to count how many times each unique tuple appears. Python's collections.defaultdict provides an elegant solution for counting occurrences without manually checking if keys exist. Using collections.defaultdict The defaultdict(int) automatically initializes missing keys with a default value of 0, making counting operations simple ? import collections my_result = collections.defaultdict(int) my_list = [[('Hello', 'Hey')], [('Jane', 'Will')], [('William', 'John')], [('Hello', 'Hey')], [('z', 'q')]] print("The list of list is:") print(my_list) for elem in my_list: my_result[elem[0]] += 1 print("The result is:") print(my_result) ... Read More

Python program to count Bidirectional Tuple Pairs

AmitDiwan
Updated on 25-Mar-2026 18:45:31

271 Views

When it is required to count the number of bidirectional tuple pairs in a list of tuples, we can iterate over the list using nested loops and check if pairs are reverse of each other. A bidirectional pair means if we have tuple (a, b), there exists another tuple (b, a) in the list. Below is a demonstration of the same − Example my_list = [(45, 67), (11, 23), (67, 45), (23, 11), (0, 9), (67, 45)] print("The list is : ") print(my_list) my_result = 0 for idx in range(0, len(my_list)): ... Read More

Python Program to Find the Sum of all Nodes in a Tree

AmitDiwan
Updated on 25-Mar-2026 18:45:15

494 Views

Finding the sum of all nodes in a tree is a fundamental operation in tree data structures. This can be accomplished using a Tree_structure class with methods to add nodes and calculate the total sum recursively. Tree Structure Implementation The following example demonstrates a complete tree implementation with sum calculation ? class Tree_structure: def __init__(self, data=None): self.key = data self.children = [] def set_root(self, data): ... Read More

Python Program to Count Number of Non Leaf Nodes of a given Tree

AmitDiwan
Updated on 25-Mar-2026 18:44:53

303 Views

When it is required to find the count of the non-leaf nodes in a Tree, a Tree_structure class is created with methods to set a root value, add nodes, and count non-leaf nodes. A non-leaf node is any node that has at least one child. Below is a demonstration of the same − What are Non-Leaf Nodes? In a tree data structure: Leaf nodes − nodes with no children Non-leaf nodes − nodes that have at least one child (also called internal nodes) 34 Non-leaf ... Read More

Python Program to Count Number of Leaf Node in a Tree

AmitDiwan
Updated on 25-Mar-2026 18:44:28

733 Views

A leaf node in a tree is a node that has no children. In this program, we'll create a tree structure and implement a method to count all leaf nodes using recursive traversal. Understanding Leaf Nodes A leaf node is identified by having an empty children list. We'll use a helper function to recursively traverse the tree and collect all leaf nodes ? Tree Structure Implementation class Tree_structure: def __init__(self, data=None): self.key = data self.children ... Read More

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

Ashish Anand
Updated on 25-Mar-2026 18:44:05

517 Views

In this article, we will see how to use Boto3 to get the list of all triggers present in an AWS Glue Data Catalog. AWS Glue triggers are used to start jobs or crawlers based on schedules or events. Prerequisites Before running this code, ensure you have: AWS credentials configured (via AWS CLI, IAM role, or environment variables) Boto3 library installed: pip install boto3 Appropriate IAM permissions for AWS Glue operations Approach The solution involves these key steps: Step 1: Import boto3 and botocore exceptions to handle errors Step 2: Create ... Read More

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

Ashish Anand
Updated on 25-Mar-2026 18:43:40

450 Views

In this article, we will see how a user can get the list of all schemas present in an AWS account using the Boto3 library. AWS Glue Data Catalog stores schema information that can be retrieved programmatically. Problem Statement Use boto3 library in Python to get the list of all schemas available in an AWS Glue Data Catalog. Prerequisites Before running the code, ensure you have: AWS credentials configured (via AWS CLI, IAM roles, or environment variables) Boto3 library installed: pip install boto3 Appropriate IAM ... Read More

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

Ashish Anand
Updated on 25-Mar-2026 18:43:20

215 Views

In this article, we will see how a user can get the list of all registries present in an AWS account using the boto3 library in Python. What are AWS Glue Registries? AWS Glue registries are containers for schema versions in the AWS Glue Schema Registry. They help organize and manage schemas for data serialization and deserialization across different services. Prerequisites AWS credentials configured (AWS CLI, environment variables, or IAM roles) boto3 library installed: pip install boto3 Appropriate IAM permissions for AWS Glue operations Approach to List Registries Step 1: Import ... Read More

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

Ashish Anand
Updated on 25-Mar-2026 18:42:56

562 Views

In this article, we will see how to get the list of all crawlers present in an AWS account using the boto3 library in Python. What are AWS Glue Crawlers? AWS Glue crawlers are programs that connect to data stores, determine data schemas, and populate the AWS Glue Data Catalog with table definitions. The list_crawlers() method helps retrieve all crawler names from your AWS Glue service. Prerequisites Before running the code, ensure you have: AWS credentials configured (via AWS CLI, IAM role, or environment variables) boto3 library installed: pip install boto3 Appropriate permissions to ... Read More

How to get the details of a workflow using Boto3

Ashish Anand
Updated on 25-Mar-2026 18:42:37

450 Views

In this article, we will see how to retrieve the resource metadata of an AWS Glue workflow using Boto3. AWS Glue workflows organize and coordinate multiple jobs, crawlers, and triggers into a single unit. What is AWS Glue Workflow? An AWS Glue workflow is a collection of related jobs, crawlers, and triggers that work together to complete an ETL process. You can visualize and track the progress of the entire workflow through the AWS Glue console. Approach to Get Workflow Details Step 1: Import boto3 and botocore exceptions to handle errors. Step 2: The workflow_name ... Read More

Advertisements