- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 10784 Articles for Python
2K+ Views
Suppose we have a baseball game point recorder. We have a list of strings; each string can be one of the 4 following types −Integer (one round's score) − Indicates the number of points we get in this round."+" (one round's score) − Indicates the points we get in this round are the sum of the last two valid round's points."D" (one round's score ) − Indicates the points we get in this round are the doubled data of the last valid round's points."C" (an operation, which isn't a round's score) − Indicates the last valid round's points we get ... Read More
682 Views
Suppose we have a binary tree we have to make a string consists of parenthesis and integers from a binary tree with the preorder traversing way. A null node will be represented by empty parenthesis pair "()". And we need to omit all the empty parenthesis pairs that don't affect the one-to-one mapping relationship between the string and the original binary tree.So, if the input is likethen the output will be 5(6()(8))(7)To solve this, we will follow these steps −ans := blank stringDefine a function pot(). This will take node, sif is null, thenreturn blank stringif if left or right ... Read More
192 Views
Suppose we have to design a standard heater with a fixed warm radius to warm all the houses. Now, we have given positions of houses and heaters on a horizontal line, we have to find the minimum radius of heaters so that all houses could be covered by those heaters. So, we will provide houses and heaters separately, and our expected output will be the minimum radius standard of heaters.So, if the input is like [1, 2, 3, 4], [1, 4], then the output will be 1 as the two heaters was placed in position 1 and 4. We have ... Read More
251 Views
Suppose we have n points in the plane that are all pairwise distinct. Now a "boomerang" is a tuple of points like (i, j, k) such that the distance between i and j is the same as the distance between i and k. We have to find the number of boomerangs.So, if the input is like [[0, 0], [1, 0], [2, 0]], then the output will be 2, as two boomerangs are [[1, 0], [0, 0], [2, 0]] and [[1, 0], [2, 0], [0, 0]].To solve this, we will follow these steps −counter_of_boomerangs := 0for each point_1 in points array, ... Read More
156 Views
Suppose we have an array num and another value val, we have to remove all instances of that value in-place and find the new length.So, if the input is like [0, 1, 5, 5, 3, 0, 4, 5] 5, then the output will be 5.To solve this, we will follow these steps −count := 0for each index i of numsif nums[i] is not equal to val, then −nums[count] := nums[i]count := count + 1return countExampleLet us see the following implementation to get a better understanding − Live Democlass Solution: def removeElement(self, nums, val): count = 0 ... Read More
5K+ Views
IPv4 and IPv6 are internet protocol versions, with IPv6 being an upgraded version of IPv4. There are several differences between the IPv4 and IPv6 protocols, including their functionality, but the most important difference is the quantity of addresses (Address space) that they create.Read through this article to find out more about IPv4 and IPv6 and how they are different from each other.What is Internet Protocol (IP)?The Internet Protocol is a set of rules that allows our computers to communicate via the Internet. IP addresses are basically in charge of directing the data packets to their correct destinations. IP controls all ... Read More
2K+ Views
Suppose we have a number. The number can be anything in between 0 to 231 – 1. We have to convert the number into words. So if the number is like 512, then the result will be Five hundred twelve.To solve this, we will follow these steps −Define some lists like less_than_20, this will hold all words from one to nineteenAnother array like tens to hold tens, twenty, thirty and so on up to ninetyAnother array for thousands, to hold thousand, million and billionDefine one function called helper(), this will take nif n is 0, then return blank stringotherwise when ... Read More
460 Views
Two lists are given. We need to find the index of the elements from the first list whose values match with the elements in the second list.With indexWe simply design follow to get the value of the element in the second list and extract the corresponding index from the first list.Example Live DemolistA = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'] listB = ['Tue', 'Fri'] # Given lists print("The given list: ", listA) print("The list of values: ", listB) # using indices res = [listA.index(i) for i in listB] # Result print("The Match indices list is : ", res)OutputRunning the above code gives ... Read More
971 Views
Given a Python list we want to find out only e e the last few elements.With slicingThe number of positions to be extracted is given. Based on that we design is slicing technique to slice elements from the end of the list by using a negative sign.Example Live DemolistA = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] # Given list print("Given list : ", listA) # initializing N n = 4 # using list slicing res = listA[-n:] # print result print("The last 4 elements of the list are : ", res)OutputRunning the above code gives us the following result −Given list ... Read More
651 Views
A Python dictionary contains key value pairs. In this article we will see how to get the key of the element whose value is maximum in the given Python dictionary.With max and getWe use the get function and the max function to get the key.Example Live DemodictA = {"Mon": 3, "Tue": 11, "Wed": 8} print("Given Dictionary:", dictA) # Using max and get MaxKey = max(dictA, key=dictA.get) print("The Key with max value:", MaxKey)OutputRunning the above code gives us the following result −Given Dictionary: {'Mon': 3, 'Tue': 11, 'Wed': 8} The Key with max value: TueWith itemgetter and maxWith itemgetter function we get ... Read More