
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 33676 Articles for Programming

238 Views
Suppose we have a grid, here in each cell can have one of three values −value 0 for an empty cell;value 1 for a fresh orange;value 2 for a rotten orange.In every minute, any fresh orange that is adjacent to a rotten orange becomes rotten.We have to find the minimum number of times that must elapse until no cell has a fresh orange. If this is not possible, then return -1.So, if the input is like [[2, 1, 1], [1, 1, 0], [0, 1, 1]], then the output will be 4To solve this, we will follow these steps −minutes := ... Read More

539 Views
Suppose we have a binary tree, the root node is present at depth 0, and children of each depth k node are at depth k+1.Here two nodes of a binary tree are called cousins if they have the same depth, but have different parents.All values of the tree will be unique, and the values x and y of two different nodes in the tree. We have to check whether the nodes corresponding to the values x and y are cousins or not.So, if the input is likex = 5, y = 4, then the output will be trueTo solve this, ... Read More

8K+ Views
In this article, we are going to learn how to insert an item in a sorted list maintaining the order. Python has a built-in module called bisect that helps us to insert any element in an appropriate position in the list.Follow the below steps to write the code.Import the module bisect.Initialize list and element that need to insertThe module bisect has a method called insort that inserts an element into a list in an appropriate position. Use the method and insert the element.Print the list.Example Live Demo# importing the module import bisect # initializing the list, element numbers = [10, ... Read More

2K+ Views
In this article, we are going to learn how to intersect two dictionaries using keys. We have to create a new dictionary with common keys. Let's see an example.Input: dict_1 = {'A': 1, 'B': 2, 'C': 3} dict_2 = {'A': 1, 'C': 4, 'D': 5} Output: {'A': 1, 'C': 3}We are going to use the dictionary comprehension to solve the problem. Follow the below steps to write the code.Initialize dictionaries.Iterate over the dictionary one and add elements that are not in dictionary two.Print the result.Example Live Demo# initializing the dictionaries dict_1 = {'A': 1, 'B': 2, 'C': 3} dict_2 = ... Read More

1K+ Views
In this article, we are going to see how to intersect two lists that contain multiple lists in different ways. Let's start in the traditional way.Follow the below the steps to solve the problemInitialize two lists with multiple listsIterate over the first list and add the current item in the new list if it presents in the second list as well.Print the result.Example Live Demo# initializing the lists list_1 = [[1, 2], [3, 4], [5, 6]] list_2 = [[3, 4]] # finding the common items from both lists result = [sub_list for sub_list in list_1 if sub_list in list_2] ... Read More

4K+ Views
In this article, we are going to learn how to intersect two strings in different ways.Follow the below the steps to solve the problem.Initialize two strings and an empty string.Iterate over the first string and add the current character to the new string if it presents in the second string as well and not present in new string already.Print the result.Example Live Demo# initializing the string string_1 = 'tutorialspoint' string_2 = 'tut' result = '' # finding the common chars from both strings for char in string_1: if char in string_2 and not char in result: ... Read More

11K+ Views
In this article, we are going to learn how to join tuple elements in a list. It's a straightforward thing using join and map methods. Follow the below steps to complete the task.Initialize list with tuples that contain strings.Write a function called join_tuple_string that takes a tuple as arguments and return a string.Join the tuples in the list using map(join_tuple_string, list) method.Convert the result to list.Print the result.Example# initializing the list with tuples string_tuples = [('A', 'B', 'C'), ('Tutorialspoint', 'is a', 'popular', 'site', 'for tech learnings')] # function that converts tuple to string def join_tuple_string(strings_tuple) -> str: return ... Read More

315 Views
In this article, we are going to learn how to join adjacent words in a list, not digits. Follow the below steps to solve the problem.Initialize the list.Find the words that are not digits using isalpha method.4Join the words using join method.Add all the digits at the end by finding them using the isdigit method.Print the result.Example Live Demo# initialzing the list strings = ['Tutorials', '56', '45', 'point', '1', '4'] # result result = [] words = [element for element in strings if element.isalpha()] digits = [element for element in strings if element.isdigit()] # adding the elements to ... Read More

434 Views
In this article, we are going to learn how to join Unicode list elements. Follow the below steps to write the code.Initialize the list.Convert all the elements into Unicode using map and string.encode methods.Convert each encoded string using the decode method.Join the strings using join method.Print the result.Example Live Demo# initializing the list strings = ['Tutorialspoint', 'is a popular', 'site', 'for tech leranings'] def get_unicode(string): return string.encode() # converting to unicode strings_unicode = map(get_unicode, strings) # joining the unicodes result = ' '.join(unicode.decode() for unicode in strings_unicode) # printing the result print(result)If you run the above code, ... Read More

1K+ Views
In this article, we are going to learn how to find the possible largest number from the given list of numbers. We will see two different ways to find to solve the problem. Follow the below steps to solve the problem.Import the itertools module for permutations method.Initialize the list with numbers and an empty list.Iterate over the permutations of the list.Join all the combinations and add the result to the empty list.Find the max number from the result with max method and key as int.Convert the string to integer and print it.ExampleLet's see the code. Live Demo# importing the module import ... Read More