
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

2K+ Views
Suppose we have a list of numbers called nums. We have to check whether the elements present in nums are forming AP series or not. As we know in AP (Arithmetic Progression) series the common difference between any two consecutive elements is the same.So, if the input is like nums = [9, 1, 17, 5, 13], then the output will be True because if we sort them, it will be [1, 5, 9, 13, 17] and here common difference is 4 for each pair of elements.To solve this, we will follow these steps −nums := sort the list numsif number ... Read More

2K+ Views
Suppoe we have an array with distinct elements called salary where salary[i] is the salary of ith employee. We have to find the average salary of employees excluding the minimum and maximum salary.So, if the input is like salary = [8000, 6000, 2000, 8500, 2500, 4000], then the output will be 5125.0, as the minimum and maximum salary values are 2000 and 8500, so excluding them the average salary values are [8000, 6000, 2500, 4000] so the average is (8000 + 6000 + 2500 + 4000)/4 = 5125.To solve this, we will follow these steps −delete minimum of salary from ... Read More

853 Views
Suppose we have an integer n and another integer start. We have to create an array called nums where nums[i] = start + 2*i (i start from 0) and n is the size of nums. Then find the bitwise XOR of all elements of nums.So, if the input is like n = 6, start = 2, then the output will be 14 because the array will be like [2+2*0, 2+2*1, ... 2+2*5] = [2, 4, 6, 8, 10, 12], then XOR of each element present in the array is 14.To solve this, we will follow these steps −count := startwhile ... Read More

4K+ Views
Suppose we have an array nums. The running sum of an array as rs[i] is sum of all elements from nums[0] to nums[i]. Finally return the entire running sum of nums.So, if the input is like nums = [8, 3, 6, 2, 1, 4, 5], then the output will be [8, 11, 17, 19, 20, 24, 29], becausers[0] = nums[0] rs[1] = sum of nums[0..1] = 8 + 3 = 11 rs[2] = sum of nums[0..2] = 8 + 3 + 6 = 17 and so onTo solve this, we will follow these steps −n:= size of numsrs:= [nums[0]]for i ... Read More

1K+ Views
Suppose we have an array called prices where prices[i] represents price of the ith item in a shop. There is a special offer going on, if we buy the ith item, then we will get a discount equivalent to prices[j] where j is the minimum index such that j > i and price of jth item is less or same as price of ith item (i.e. prices[j] = prices[j], thenprices[i] := prices[i] - prices[j]come out from the loopotherwise, j := j + 1return pricesExample (Python)Let us see the following implementation to get better understanding − Live Demodef solve(prices): for i ... Read More

309 Views
Suppose we are given a linked list that has the start node as "head", and two integer numbers m and n. We have to traverse the list and delete some nodes such as the first m nodes are kept in the list and the next n nodes after the first m nodes are deleted. We perform this until we encounter the end of the linked list. We start from the head node, and the modified linked list is to be returned.The linked list structure is given to us as −Node value : next : So, if the ... Read More

2K+ Views
To show multiple colorbars in matplotlib, we can take the following steps−Set the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Initialize a variable N for the number of sample data.Create random data1 using numpy.Display data as an image, i.e., on a 2D regular raster, with data1.Add a colorbar to a plot.Repeat steps 4, 5, and 6, with different datasets and axes.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, (ax1, ax2) = plt.subplots(nrows=2, ncols=1) N ... Read More

7K+ Views
To show a plot in Flask, we can take the following steps−Make a small application.To run Flask application, go to the current directory.$ export FLASK_APP=file.py$ flask runOpen the browser, hit url:http://127.0.0.1:5000/print-plot/To plot the figure, we can create data points for x and y using random.Plot data points, x and y, on the created axis.Write a figure into png figure format.Retrieve the entire contents of the BytesIO object.Exampleimport io from flask import Response from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.figure import Figure from flask import Flask import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True app = Flask(__name__) ... Read More

615 Views
To write unit test cases against a code, we can consider a plot that takes an array as x points and plot it as y=x^2. While testing, we would extract y_data for x data points.−StepsCreate a method, i.e., plot_sqr_curve(x) to plot x and x^2 using plot() method and return the plot.To test, use unittest.TestCase.Write test_curve_sqr_plot() method that includes the following statements.Create data points for x to plot the curve.Using the above x data points, create y data points.Using x and y data points, plot the curve.Using pt (from step 5), extract x and y data.Check whether the given expression is ... Read More

3K+ Views
To store mouse event coordinates with matplotlib, we can use "button_press_event" event.−StepsSet the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Plot a line in the range of 10Bind the function *onclick* to the event *button_press_event*.Print the x and y data of the event.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt plt.rcParams['backend'] = 'TkAgg' plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Function to print mouse click event coordinates def onclick(event): print([event.xdata, event.ydata]) # Create a figure and a set of subplots fig, ... Read More