Found 26504 Articles for Server Side Programming

Python Program that Displays which Letters are Present in Both the Strings

AmitDiwan
Updated on 11-Mar-2021 12:44:01

783 Views

When it is required to display the letters common to two strings, the ‘set’ method can be used.Python comes with a datatype known as ‘set’. This ‘set’ contains elements that are unique only.The set is useful in performing operations such as intersection, difference, union and symmetric difference.Below is a demonstration for the same −Example Live Demostring_1 = 'hey' string_2 = 'jane' print("The first string is :") print(string_1) print("The second string is :") print(string_2) my_result = list(set(string_1)|set(string_2)) print("The letters are : ") for i in my_result:    print(i)OutputThe first string is : hey The second string is : jane The letters are ... Read More

Python Program to Find Longest Common Substring using Dynamic Programming with Bottom-Up Approach

AmitDiwan
Updated on 11-Mar-2021 12:41:24

304 Views

When it is required to find longest common substring using dynamic programming with bottom-up approach, a method can be defined, that computes the solution to smaller problems. These smaller problem results don’t need to be computed again and again. Instead, they can just be accessed when required. This would lead to developing a solution to the bigger problem in hand.Below is a demonstration for the same −Example Live Demodef compute_lcw(string_1, string_2):    val = [[-1]*(len(string_2) + 1) for _ in range(len(string_1) + 1)]    for i in range(len(string_1) + 1):       val[i][len(string_2)] = 0    for j in range(len(string_2)): ... Read More

Python - Assign a specific value to Non Max-Min elements in Tuple

AmitDiwan
Updated on 11-Mar-2021 12:39:14

118 Views

When it is required to assign a specific value to the non max-min elements in a tuple, the ‘max’ method, the ‘min’ method, the ‘tuple’ method and a loop can be used.The ‘max’ method returns the maximum value among all of the elements in an iterable. The ‘min’ method returns the minimum value among all of the elements in an iterable.The ‘tuple’ method converts a given value/iterable into a tuple type.Below is a demonstration for the same −Example Live Demomy_tuple = (25, 56, 78, 91, 23, 11, 0, 99, 32, 10) print("The tuple is : ") print(my_tuple) K = 5 print("K ... Read More

Python program to sort a list of tuples by second Item

AmitDiwan
Updated on 11-Mar-2021 12:36:43

633 Views

When it is required to sort a list of tuples based on the second item, the lambda function and ‘sorted’ method can be used.A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on). A list of tuple basically contains tuples enclosed in a list.Anonymous function is a function which is defined without a name.In general, functions in Python are defined using ‘def’ keyword, but anonymous function is defined with the help of ‘lambda’ keyword. It takes a single expression, but can take any number of arguments. It ... Read More

Python Program to Print an Identity Matrix

AmitDiwan
Updated on 11-Mar-2021 12:35:14

835 Views

When it is required to print an identity matrix, nested loops can be used.Below is a demonstration for the same −Example Live Demon = 4 print("The value of n has been initialized to " +str(n)) for i in range(0, n):    for j in range(0, n):       if(i==j):          print("1", sep=" ", end=" ")       else:          print("0", sep=" ", end=" ")    print()OutputThe value of n has been initialized to 4 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1ExplanationThe value of ‘n’ ... Read More

Python program to search an element in a doubly linked list

AmitDiwan
Updated on 11-Mar-2021 12:33:43

550 Views

When it is required to search for an element in a doubly linked list, a ‘Node’ class needs to be created. In this class, there are three attributes, the data that is present in the node, the access to the next node of the linked list, and the access to the previous node of the linked list.Another class needs to be created that would have an initialization function, and the head of the node would be initialized to ‘None’ inside this.Multiple methods are defined by the user to add node to the linked list, to display the nodes it and ... Read More

Python program to rotate doubly linked list by N nodes

AmitDiwan
Updated on 11-Mar-2021 12:30:33

263 Views

When it is required to rotate a doubly linked list by a specific number of nodes, a ‘Node’ class needs to be created. In this class, there are three attributes, the data that is present in the node, the access to the next node of the linked list, and the access to the previous node of the linked list.Below is a demonstration for the same −Example Live Democlass Node:    def __init__(self, my_data):       self.previous = None       self.data = my_data       self.next = None class double_list:    def __init__(self):       self.head = ... Read More

Python program to remove duplicate elements from a Doubly Linked List

AmitDiwan
Updated on 11-Mar-2021 12:28:04

275 Views

When it is required to remove the duplicate elements in a doubly linked list, a ‘Node’ class needs to be created. In this class, there are three attributes, the data that is present in the node, the access to the next node of the linked list, and the access to the previous node of the linked list.Below is a demonstration for the same −Example Live Democlass Node:    def __init__(self, my_data):       self.previous = None       self.data = my_data       self.next = None class double_list:    def __init__(self):       self.head = None   ... Read More

Python program to insert a new node at the middle of the Doubly Linked List

AmitDiwan
Updated on 11-Mar-2021 12:23:46

366 Views

When it is required to insert a new node in the middle of a doubly linked list, a ‘Node’ class needs to be created. In this class, there are three attributes, the data that is present in the node, the access to the next node of the linked list, and the access to the previous node of the linked list.Below is a demonstration for the same −Example Live Democlass Node:    def __init__(self, my_data):       self.previous = None       self.data = my_data       self.next = None class double_list:    def __init__(self):       self.head ... Read More

Python program to insert a new node at the end of the Doubly Linked List

AmitDiwan
Updated on 11-Mar-2021 12:19:49

546 Views

When it is required to insert a new node at the end of a doubly linked list, a ‘Node’ class needs to be created. In this class, there are three attributes, the data that is present in the node, the access to the next node of the linked list, and the access to the previous node of the linked list.Below is a demonstration for the same −Example Live Democlass Node:    def __init__(self, my_data):       self.prev = None       self.data = my_data       self.next = None class double_list:    def __init__(self):       self.head ... Read More

Advertisements