
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

301 Views
Suppose we have one regular polygon with n sides represented as a binary string of size n. The vertices can be colored either in blue (0) or in red (1). They are colored in clockwise direction We have to count number of isosceles triangles whose vertices are vertices of the regular polygon, and their colors are same.So, if the input is like polygon = "111010", then the output will be 2 becausethere are two triangles ACE and AFE.To solve this, we will follow these steps −Define a function all() . This will take nif n mod 2 is same as ... Read More

229 Views
Suppose, we are provided with two strings. The first one has a length greater than the second one, and we have to check if the substrings from the first string match exactly with the second string or differ in one position. We return the indexes of the first string, where the substrings that can match with the second string start.So, if the input is like string1 = 'tpoint', string2 = 'pi', then the output will be 1 2.The substring from the first string that matches with the second string or differs in one position at index 1 and 2 are ... Read More

360 Views
Suppose we have two arrays called nums1 and nums2, they have same number of elements N. Now consider a set S with N elements from 1 through N. We have to find the value of (nums1[i1] + nums1[i2] + ... nums1[ik])^2 + (nums2[i1] + nums2[i2] + ... nums2[ik])^2 where {i1, i2, ... ik} is non empty subset of the set S.So, if the input is like nums1 = [-1, 6] nums2 = [5, 4], then the output will be 106 because(-1)^2 + (5)^2 = 26(6)^2 + (4)^2 = 50(-1 + 6)^2 + (5 + 4)^2 = 106To solve this, we ... Read More

182 Views
Suppose, we are given a string 'input_str'. If we determine all the suffixes from input_str; for example if the string is 'abcd', the suffixes are 'abc', 'bcd', 'cd', 'd'. Now, we check the similarity between input_str and all the suffixes by the length of the longest common prefix in input_str and a suffix. The sum of the similarities between input_str and all the suffixes has to be returned.So, if the input is like input_str = 'tpotp', then the output will be 7All the suffixes from the string 'tpotp' are 'tpotp', 'potp', 'otp', 'tp', and 'p'.If we check the similarity of ... Read More

122 Views
Suppose, we are given a string 'input_str'. Now, we are asked to determine every possible substring from the given string then concatenate all the substrings one after another in a lexical order into another string. We are also provided an integer value k. Our task is to return the letter at index k from the concatenated string.So, if the input is like input_str = 'pqrs', k = 6, then the output will be pThe substrings from the given string in lexical order are p, pq, pqr, pqrs, q, qr, qrs, r, rs, s.If we concatenate the strings, it becomes ppqpqrpqrsqqrqrsrrss. ... Read More

829 Views
To curve text in a polar plot in matplotlib we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure.Add an 'ax' to the figure as part of a subplot arrangement.Plot the line with some degree, color='green' and linewidth=2.Create x and y data points, with some curve and plot them using plot() method.To display the figure, use Show() method.Examplefrom matplotlib import pyplot as plt from scipy.interpolate import interp1d import numpy as np plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax ... Read More

4K+ Views
To animate with contours in matplotlib, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create data for the contour plot.Create a figure and a set of subplots.Generate an animation by repeatedly calling a function *animate* where the animate() method changes the contour data points.To display the figure, use Show() method.Exampleimport numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Random data for the contour plot data = np.random.randn(800).reshape(10, 10, 8) # Create a ... Read More

2K+ Views
plt.figure() − Creates a new figure or activates an existing figure.plt.subplots() − Creates a figure and a set of subplots.Let's take an example to understand the difference between plt.subplots() and plt.figure().StepsSet the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure. Use plt.figure() method.Create a figure and a set of subplots. Use plt.subplots() method.To display the figure, use Show() method.Examplefrom matplotlib import pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Create a new figure using plt.figure fig1 = plt.figure("Figure 1 ... Read More

5K+ Views
To get the (x, y) positions pointing with mouse in an interactive plot, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure.Bind the function *mouse_event* to the event *button_press_event*.Create x and y data points using numpy.Plot the x and y data points using plot() method.To display the figure, use Show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True def mouse_event(event): print('x: {} and y: {}'.format(event.xdata, event.ydata)) fig = ... Read More

199 Views
Suppose, we are given a number n and are asked to write all the possible permutations with the positive integers up to n. The permutations are then sorted lexicographically and numbered from 1 to n. Among all the permutations, one permutation is taken and is termed as the special permutation. Now, among the special permutation; the values can be forgotten. The forgotten values are then replaced with 0s. We have to find the permutations that can be equal to the original permutations and then we add their perspective number to obtain a sum. The sum value is returned as the ... Read More