
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 10476 Articles for Python

290 Views
Suppose we have a number x and another number n. We have to find number of ways we can get x as sum of nth power of some unique numbers.So, if the input is like x = 100 n = 2, then the output will be 3 because possible solutions are 6^2 + 8^2, 10^2 and 1^2 + 3^2 + 4^2 + 5^2 + 7^2.To solve this, we will follow these steps −ans := 0Define a method called solve() this will take four parameters x, n, cn and cs, the initialvalues for cs = 0, cn = 1p := cn^nwhile ... Read More

932 Views
Suppose we have one alphanumeric string s. We have to sort it based on following conditionAll sorted lowercase letters will be placed before uppercase letters.All sorted uppercase letters will be placed before digits.All sorted odd digits will be placed before sorted even digits.So, if the input is like s = "HeLlo1234", then the output will be eloHL1324To solve this, we will follow these steps −Define a function f() . This will take ccode := 0if c is in upper case, thencode := 10^3otherwise when c is a digit, thencode := 10^6if ASCII of c is even, thencode := 10^9return code ... Read More

419 Views
Suppose we have a 2d list containing information about athletes. This information is rank, age, height. Each row contains information for different athletes. We also have another number k. We have to sort the data based on kth attribute.So, if the input is likeRankageheight125190235180333185426175535180And k = 1.then the output will beRankageheight125190426175333185235180535180[[1, 25, 190], [4, 26, 175], [3, 33, 185], [2, 35, 180], [5, 35, 180]]To solve this, we will follow these steps −Call the sort() function for the 2d array called infodefine one function that sort based on kth argument and pass it to the key parameter of sort() function.ExampleLet ... Read More

326 Views
Suppose we have two strings s and t (both contains lowercase English letters). We have to find a list of pairs of size 3, where each pair is in this form (l, k) here k is a string and l is its length. Now among these three pairs, first one contains substring of s and t which is longest common prefix p of these two strings, then the remaining part of s is s' and remaining part of t is t'. So final list will be like [(length of p, p), (length of s', s'), (length of t', t')].So, if ... Read More

21K+ Views
Suppose we have a string s. We have to compress this string into Run length encoding form. So when a character is repeated k number of times consecutively like 'bbbb' here letter 'b' is repeated four times consecutively, so the encoded form will be 'b4'. For single characters we shall not add the count into it.So, if the input is like s = "abbbaaaaaaccdaaab", then the output will be ab3a6c2da3bTo solve this, we will follow these steps −res := blank stringcnt := 1for i in range 1 to size of s - 1, doif s[i - 1] is same as ... Read More

15K+ Views
Suppose we have a string s. We have to swap all odd positioned elements with the even positioned elements. So finally we shall get a permutation of s where elements are pairwise swapped.So, if the input is like s = "programming", then the output will be "rpgoarmmnig"To solve this, we will follow these steps −s := make a list from the characters of sfor i in range 0 to size of s - 1, increase by 2, doswap s[i], s[i+1] with s[i+1], s[i]join characters from s to make whole string and returnExampleLet us see the following implementation to get better ... Read More

5K+ Views
Suppose we want to do complex number tasks by defining a complex number class with following operations −add() to add two complex numberssub() to subtract two complex numbersmul() to multiply two complex numbersdiv() to divide two complex numbersmod() to get modulus of complex numbersThe complex numbers will be shown in the form (a + bi). We have two complex numbers, will perform these operations on them. Inside the class we overload the add(), sub(), mul() and div() methods so that we can use the operators to perform the operations. We also overload __str__() method to print the complex number in ... Read More

1K+ Views
Suppose we have a number n. We have to print a triangle with n rows and each line will hold line number i, i number of times.So, if the input is like n = 5, then the output will be1 22 333 4444 55555To solve this, we will follow these steps −for i in range 1 to n, dodisplay (integer part of (10^i)/9*i)go to next lineExampleLet us see the following implementation to get better understanding −def solve(n): for i in range(1,n+1): print((10**i)//9*i) n = 8 solve(n)Input8 Output1 22 333 4444 55555 666666 7777777 88888888

465 Views
Suppose we have an array with n different English letters. We also have another value k. We can select k different indices (1-indexed) with uniform distribution. We have to find the probability that at least one of the k indices selected will contain the letter 'a'.So, if the input is like letters = ['a', 'c', 'a', 'b', 'l', 'a', 'b', 'z'] k = 2, then the output will be 64.28%. There are combinations like (1, 2), (1, 3) like there are 28 combinations but some of them like (1, 2), (1, 3), (6, 7) such 18 pairs are holding 7, ... Read More

15K+ Views
Suppose we have a number n. We have to generate Pascal's triangle up to n lines. The Pascal's triangle will be look like this −The property of Pascal's triangle is the sum of each adjacent two numbers of previous row is the value of the number which is placed just below on the second row. For example, the first 10 at row 6 is sum of 4 and 6 at row 5 and second 10 is sum of two numbers 6 and 4 at row 5.So, if the input is like n = 5, then the output will be ... Read More