
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

410 Views
Suppose we have a string with lowercase ASCII characters, we have to find all distinct continuous palindromic substrings of it.So, if the input is like "bddaaa", then the output will be [a, aa, aaa, b, d, dd]To solve this, we will follow these steps −m := a new mapn := size of smatrix := make two rows of n number of 0ss := "@" concatenate s concatenate "#"for j in range 0 to 1, dotemp := 0matrix[j, 0] := 0i := 1while i

220 Views
Suppose we have a number n; we have to check a lower case stringof length n+1 so that the character at any position should be lexicographically bigger than its immediate next character.So, if the input is like 15, then the output will be ponmlkjihgfedcba.To solve this, we will follow these steps −temp_str := blank stringextra := n mod 26if extra >= 1, thenfor i in range 26 -(extra + 1) to 25, dotemp_str := temp_str + str[i]count := n / 26 (integer division)for i in range 1 to count + 1, dofor j in range 0 to 25, dotemp_str := ... Read More

197 Views
Suppose we have an array with N numbers, we have to check whether the 3 elements such that b[i]< b[j] < b[k] and i < j < k in linear (O(n)) time. If there are multiple such triplets, then print any one of them.So, if the input is like [13, 12, 11, 6, 7, 3, 31], then the output will be [6, 7, 31]To solve this, we will follow these steps −n := size of Amaximum := n-1, minimum := 0smaller := an array of size 1000, and fill with 0smaller[0] := -1for i in range 1 to n, doif ... Read More

150 Views
Suppose we have a number N, we have to find a positive number M such that gcd(N^M, N&M) is as large as possible and m < n. We will also return the largest gcd thus obtained.So, if the input is like 20, then the output will be 31To solve this, we will follow these steps −if bit_count(n) is same as 0, thenfor i in range 2 to int(square root of (n)) + 1, doif n mod i is same as 0, thenreturn int(n / i)otherwise, val := 0p :=dupn := nwhile n is non-zero, doif (n AND 1) is same ... Read More

148 Views
Suppose we have a string S. The length is n. These n boxes adjacent to each other, a character R at position i represents that i-th box is being pushed towards right. similarly, L at position i represents that i-th box is being pushed towards left, a dot '.' indicates an empty space. Starting from initial configuration, at every time unit, a box being pushed to the right side is able to push next box to right, same action can be applied for the left side also. We have to find the final positions of all boxes when no more ... Read More

2K+ Views
Pandas is a very widely used python library for data cleansing, data analysis etc. In this article we will see how we can use the query method to fetch specific data from a given data set. We can have both single and multiple conditions inside a query.Reading the dataLet’s first read the data into a pandas data frame using the pandas library. The below program just does that.Exampleimport pandas as pd # Reading data frame from csv file data = pd.read_csv("D:\heart.csv") print(data)OutputRunning the above code gives us the following result −Query with single conditionNext we see how we ... Read More

507 Views
As part of data cleansing activities, we may sometimes need to take out the integers present in a list. In this article we will have an array containing both floats and integers. We will remove the integers from the array and print out the floats.With astypeThe astype function will be used to find if an element from the array is an integer or not. Accordingly we will decide to keep or remove the element from the array and store it in the result set.Example Live Demoimport numpy as np # initialising array A_array = np.array([3.2, 5.5, 2.0, 4.1, 5]) ... Read More

2K+ Views
Sometimes in a Python dictionary we may need to to filter out certain keys of the dictionary based on certain criteria. In this article we will see how to filter out keys from Python dictionary.With for and inIn this approach we put the values of the keys to be filtered in a list. Then iterate through each element of the list and check for its presence in the given dictionary. We create a resulting dictionary containing these values which are found in the dictionary.Example Live DemodictA= {'Mon':'Phy', 'Tue':'chem', 'Wed':'Math', 'Thu':'Bio'} key_list = ['Tue', 'Thu'] print("Given Dictionary:", dictA) print("Keys for filter:", ... Read More

1K+ Views
Both abs() and fabs() represent the mathematical functions which give us the absolute value of numbers. But there is a subtle difference between both of them which we can explore in the exmaples below.ExampleThe abs() functions returns the absolute value as an integer or floating point value depending on what value was supplied dot it. But the fabs) function will always return the value as floating point irrespective of whether an integer or a floating point was supplied to it as a parameter. Live Demoimport math n = -23 print(abs(n)) print(math.fabs(n)) n = 21.4 print(abs(n)) print(math.fabs(n)) n = ... Read More

1K+ Views
The print() function in python always creates a newline. But there is also a parameter for this function which can put other characters instead of new line at the end. In this article we will explore various options for this parameter.ExampleIn the below example we see various ways we can assign values to the end parameter and see the result from it. Live Demoprint("Welcome to ") print("Tutorialspoint") print("Welcome to ", end = ' ') print("Tutorialspoint") print("emailid", end='@') print("tutorialspoint.com")OutputRunning the above code gives us the following result −Welcome to Tutorialspoint Welcome to Tutorialspoint emailid@tutorialspoint.comRead More