[Google Interview] How To Find The Peak Element In Python?
Finding Peak Element in an array using Linear Search and Binary Search Methods.
Finding Peak Element in an array using Linear Search and Binary Search Methods.
Seaborn is a comprehensive data visualization library used for the plotting of statistical graphs in Python. It provides fine-looking default styles and color schemes for making more attractive statistical plots. Seaborn is built on the top portion of the matplotlib library and is also integrated closely with data structures from pandas. How to change … Read more
Trick #1: Slicing and Slice Assignment This one-liner demonstrates the power of three interesting NumPy features and how their combination can solve a small data science problem in a clean and efficient manner. Say, you are working at a company and the accountant asks you to analyze salary data of different employees in your company. … Read more
Problem Formulation Given a basic Python program. How to print an exception if it occurs without exiting the program? For example, consider the following program that raises a ZeroDivisionError: division by zero. The output is: You want the program to keep running and executing the print statement after giving you a note about the exception: … Read more
Problem Formulation Given a list of lists lst, and Given an element x. How to find the row and column index of the element x in the list of lists lst? If the element does not occur in a list, the return value should be the tuple (-1, -1). If the element exists multiple times, … Read more
Problem Formulation Given a string containing digits such as ‘123.456’. How to convert it to a double in Python such as 123.456? Solution Python doesn’t provide an explicit “double” data type. However, it provides the float type that behaves the same and has the same precision as doubles in C, C++, or Java. To convert … Read more
To get a substring of a given string in Python, you can use a popular feature called “slicing“. The syntax is string[start:stop:step] with the following meaning: start is the index of the first character included in the substring, stop is the index of the last character, but it is not itself included in the substring, … Read more
The easiest way to select multiple columns in Pandas is to pass a list into the standard square-bracket indexing scheme. For example, the expression df[[‘Col_1’, ‘Col_4, ‘Col_7’]] would access columns ‘Col_1’, ‘Col_4’, and ‘Col_7’. This is the most flexible and concise way for only a couple of columns. To learn about the best 3 ways … Read more
Problem Formulation How to calculate the inverse of the normal cumulative distribution function (CDF) in Python? Method 1: scipy.stats.norm.ppf() In Excel, NORMSINV is the inverse of the CDF of the standard normal distribution. In Python’s SciPy library, the ppf() method of the scipy.stats.norm object is the percent point function, which is another name for the … Read more
There are four main ways to reverse a string in Python: Slicing s[::-1] with negative step size traverses the string from right to left. ”.join(reversed(s)) first creates an iterable of characters in reversed order, and then joins these characters to obtain the reversed string. A for loop using the range(len(s)-1, -1, -1) function traverses the … Read more
Problem Formulation Given two strings x and y. Create a new string xy and print it to the shell. Consider the following examples: INPUT x = ‘hi’ y = ‘finxter’ OUTPUT: hifinxter INPUT x = ‘2’ y = ‘4’ OUTPUT: 24 INPUT x = ‘abc’ y = ‘[1, 2, 3]’ OUTPUT: abc[1, 2, 3] Solution … Read more
Character Description Character U+2070 SUPERSCRIPT ZERO β° U+2071 SUPERSCRIPT LATIN SMALL LETTER I β± U+2074 SUPERSCRIPT FOUR β΄ U+2075 SUPERSCRIPT FIVE β΅ U+2076 SUPERSCRIPT SIX βΆ U+2077 SUPERSCRIPT SEVEN β· U+2078 SUPERSCRIPT EIGHT βΈ U+2079 SUPERSCRIPT NINE βΉ U+207A SUPERSCRIPT PLUS SIGN βΊ U+207B SUPERSCRIPT MINUS β» U+207C SUPERSCRIPT EQUALS SIGN βΌ U+207D SUPERSCRIPT LEFT … Read more