Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Programming Articles
Page 21 of 2547
Check whether a number has consecutive 0's in the given base or not using Python
When working with different number bases, we sometimes need to check if a number contains consecutive zeros in its representation. Python provides an efficient way to convert numbers between bases and detect patterns like consecutive zeros. Understanding the Problem For example, the number 8 in base 2 (binary) is represented as "1000", which contains consecutive zeros. We need to convert the number to the specified base and then check for consecutive zero digits. Complete Solution def check_consecutive_zero(N, K): my_result = convert_to_base(N, K) if (check_consecutive_zeros(my_result)): ...
Read MorePython Program to Implement a Stack
A stack is a Last-In-First-Out (LIFO) data structure where elements are added and removed from the same end (the top). In Python, we can implement a stack using a class with methods for push, pop, and checking if the stack is empty. Stack Implementation Here's a complete stack implementation with push, pop, and empty check operations ? class Stack: def __init__(self): self.items = [] def is_empty(self): return ...
Read MoreHow to get the list of all versions of the object from S3 present in AWS Resource
In this article, we will see how to get the list of all versions of objects from S3 using boto3 in Python. This is useful when S3 versioning is enabled and you need to track object history. Prerequisites Before running this code, ensure you have ? AWS credentials configured (via AWS CLI, IAM roles, or environment variables) S3 bucket with versioning enabled boto3 library installed: pip install boto3 Approach We'll use the list_object_versions() method from the S3 client to retrieve all versions of objects in a specific bucket and prefix ? ...
Read MorePython Program To Find the Smallest and Largest Elements in the Binary Search Tree
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. Problem Statement Given the root node of a binary search tree, find the node ...
Read MoreHow to use Boto3 to paginate through all triggers present in AWS Glue
Problem Statement: Use boto3 library in Python to paginate through all triggers from AWS Glue Data Catalog that is created in your account Approach/Algorithm to solve this problem Step 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 max_items denote the total number of records to return. ...
Read MorePython Program to Find Nth Node in the Inorder Traversal of a Tree
Finding the nth node in inorder traversal of a binary tree is a common problem in tree algorithms. Inorder traversal visits nodes in the order: left subtree → root → right subtree. This article demonstrates how to find the nth node efficiently using a binary tree class with inorder traversal methods. Understanding Inorder Traversal In inorder traversal, nodes are visited in this sequence: Traverse the left subtree Visit the root node Traverse the right subtree For a binary search tree, inorder traversal gives nodes in sorted order. Binary Tree Implementation Here's a complete ...
Read MoreHow to use Boto3 to paginate through all tables present in AWS Glue
AWS Glue Data Catalog stores metadata about your data sources. When you have many tables, pagination helps retrieve them efficiently without overwhelming your application. The boto3 library provides built-in pagination support for AWS Glue operations. Understanding Pagination Parameters The pagination configuration accepts three optional parameters: max_items: Total number of records to return across all pages page_size: Number of records per page (default is 100) starting_token: Token from previous response to resume pagination Setting up AWS Glue Client First, create a boto3 session and Glue client. Ensure your AWS credentials and region are configured ...
Read MorePython Program to Convert a given Singly Linked List to a Circular List
A singly linked list can be converted to a circular linked list by making the last node point to the head node instead of None. This creates a circular structure where traversal can continue indefinitely. Node and LinkedList Structure First, we define the basic node and linked list classes ? class Node: def __init__(self, data): self.data = data self.next = None class LinkedList_struct: def __init__(self): ...
Read MoreHow to use Boto3 to paginate through table versions of a table present in AWS Glue
Problem Statement: Use boto3 library in Python to paginate through table versions of a table from AWS Glue Data Catalog that is created in your account. Approach/Algorithm to solve this problem Step 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 and table_name are required. max_items denotes the total number of records to ...
Read MorePython program to find Tuples with positive elements in List of tuples
When it is required to find tuples that have positive elements from a list of tuples, list comprehension along with the all() function can be used. This approach checks if all elements in each tuple are non-negative. Syntax result = [tuple for tuple in list_of_tuples if all(element >= 0 for element in tuple)] Example The following example demonstrates how to filter tuples containing only positive elements ? my_list = [(56, 43), (-31, 21, 23), (51, -65, 26), (24, 56)] print("The list is:") print(my_list) my_result = [sub for sub in my_list ...
Read More