AmitDiwan has Published 10744 Articles

Find yesterday’s, today’s and tomorrow’s date in Python

AmitDiwan

AmitDiwan

Updated on 15-Apr-2021 13:05:43

464 Views

When it is required to find yesterday, today and tomorrow’s date with respect to current date, the current time is determined, and a method is used (in built) that helps find previous day and next day’s dates.Below is a demonstration of the same −Example Live Demofrom datetime import datetime, timedelta ... Read More

Python Program to print the pattern ‘G’

AmitDiwan

AmitDiwan

Updated on 15-Apr-2021 13:05:23

572 Views

When it is required to print the pattern of the letter ‘G’ using ‘*’, a method can be defined, and nested loop can be used to iterate through the numbers and print ‘*” to form a ‘G’ pattern.Below is a demonstration of the same −Exampledef display_pattern(my_line):    my_pattern=""    for ... Read More

Python Program to Display Fibonacci Sequence Using Recursion

AmitDiwan

AmitDiwan

Updated on 15-Apr-2021 13:04:56

385 Views

When it is required to print the fibonacci sequence using the method of recursion, a method can be declared that calls the same method again and again until a base value is reached.Below is a demonstration of the same −Example Live Demodef fibonacci_recursion(my_val):    if my_val Read More

Python program to unique keys count for Value in Tuple List

AmitDiwan

AmitDiwan

Updated on 15-Apr-2021 12:58:40

165 Views

When it is required to get the count of unique keys for values in a list of tuple, it can be iterated over and the respective counts can be determined.Below is a demonstration of the same −Example Live Demoimport collections my_result = collections.defaultdict(int) my_list = [[('Hello', 'Hey')], [('Jane', 'Will')], [('William', ... Read More

Python program to count Bidirectional Tuple Pairs

AmitDiwan

AmitDiwan

Updated on 15-Apr-2021 12:58:16

190 Views

When it is required to count the number of bidirectional tuple pairs in a list of tuples, the list can be iterated over using nested loops, and the ‘AND’ operation is performed on the first element and result of equality between first and second element.Below is a demonstration of the ... Read More

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

AmitDiwan

AmitDiwan

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

412 Views

When it is required to get the sum of all the nodes in a Tree, a ‘Tree_structure’ class is created, methods to set a root value, and to add other values are defined. It also has a method to determine the sum of all elements of a Tree structure. Various ... Read More

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

AmitDiwan

AmitDiwan

Updated on 15-Apr-2021 12:53:32

219 Views

When it is required to find the count of the non leaf nodes in a Tree, a ‘Tree_structure’ class is created, methods to set a root value, and to add other values are defined. Various options are given that the user can select. Based on the user’s choice, the operation ... Read More

Python Program to Count Number of Leaf Node in a Tree

AmitDiwan

AmitDiwan

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

628 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 ... Read More

Python Program to Implement Queues using Stacks

AmitDiwan

AmitDiwan

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

380 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:   ... Read More

Python Program to Implement Stack Using Two Queues

AmitDiwan

AmitDiwan

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

573 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 ... Read More

Advertisements