Found 33676 Articles for Programming

Python - Display text to PyGame window

Pradeep Elance
Updated on 25-Jan-2021 07:34:15

814 Views

Pygame is a multimedia library for Python for making games and multimedia applications. In this article we will see how to use the pygame module to get customized font and text on the screen taking into consideration, its height, width, and position in the pygame window.In the below program we initialize the pygame module and then define the mode and the caption for the image. Next we add the font text and define the coordinates for the font. The screen.blit function paints the screen while the while loop keeps listening the end of the game is clicked.Exampleimport pygame import sys ... Read More

Python - Display images with PyGame

Pradeep Elance
Updated on 25-Jan-2021 07:29:48

1K+ Views

Pygame is a multimedia library for Python for making games and multimedia applications. In this article we will see how to use the pygame module to paint a picture on the screen taking into consideration, its height, width and position in the pygame window.In the below program we initialize the pygame module and then define the mode and the caption for the image. Next we load the image and define the coordinates. The screen.blit function paints the screen while the while loop keeps listening the end of the game is clicked.Exampleimport pygame pygame.init() w = 300; h = 300 screen ... Read More

Python - Delete rows/columns from DataFrame using Pandas.drop()

Pradeep Elance
Updated on 25-Jan-2021 07:29:31

905 Views

Pandas is one of the most popular python library for data analysis and data wrangling. In this article we will see how we can create a pandas dataframe and then delete some selective rows ort columns from this data frame.Deleting roewsIn the below example we have the iris.csv file which is read into a data frame. We first have a look at the existing data frame and then apply the drop function to the index column by supplying the value we want to drop. As we can see at the bottom of the result set the number of rows has ... Read More

Python - Data visualization using Bokeh

Pradeep Elance
Updated on 25-Jan-2021 07:25:18

292 Views

Bokeh is an python data visualization library for web browsers. It czncreate elegant, concise construction of versatile graphics. It is used to quickly and easily make interactive plots, dashboards, and data applications. In this article we will see how we can create various types of basic graphs using Bokeh.Plotting LinesWe can create a line plot by using the x and y coordinates of the points in it as two lists. We directly display the output in the browser by specifying the height and width of the figure. We can also supply additional parameters like width of the line and colour ... Read More

Python - Create Test DataSets using Sklearn

Pradeep Elance
Updated on 25-Jan-2021 07:19:19

356 Views

The Sklearn python library does provide sample data sets which can be used tocreate various graph plots. The usefulness of these datasets is in creating sample graphs and charts and predicting the behavior of the graph as the values changes. Also you can work on other parameters like deciding on the colours and axes etc on this sample graphs before using the actual data set.Using make_blobsIn the below example we use the sklearn library along with the matplotlib to create a scatter plot with a specific style. We choose a sample of 200 data points and also select the colour ... Read More

Find maximum length sub-list in a nested list in Python

Pradeep Elance
Updated on 25-Jan-2021 07:18:06

952 Views

we often deal with nested lists when doing data analysis in python. In this article, we will see how to find out the longest list among the elements in a nested list and then print this along with its length.Using lambda and mapWe declare a nested list and give it as input to the lambda function along with its length. Finally, we apply the max function to get the list with maximum length as well as the length of such list.Example Live Demodef longest(lst):    longestList = max(lst, key = lambda i: len(i))    maxLength = max(map(len, listA))    return longestList, ... Read More

Creating a Proxy Webserver in Python

Pradeep Elance
Updated on 25-Jan-2021 07:14:41

2K+ Views

A proxy server sits in between the client and the actual server. It receives the requests from the client, send it to the actual server, and on receiving the response from the actual server it sends the response back to the client. There are many reasons to use the proxy like hiding the server’s IP address, performance improvement or increasing security etc. In this article we will see how we can create a simple proxy server using python.The three modules SimpleWebSocketServer, , SimpleHTTPSServer and urllib can be used to achieve this. Below we see how we create python class using ... Read More

Print all possible ways to convert one string into another string in C++

sudhir sharma
Updated on 25-Jan-2021 05:29:05

261 Views

In this problem, we are given two strings str1 and str2. Our task is to create a program to Print all possible ways to convert one string into another string. Problem Description: Here, we need to find all possible ways using which we can convert str1 to str2. While converting, we can perform any of the three operations, Insert RemoveReplaceLet’s take an example to understand the problem,  Input: str1 = “kfeod” str2 = “kfcadq”OutputWay1:Insert q, after d. Replace c by e. Replace o by a.Solution ApproachWe will find the minimum number of edits first and then create a DP matrix. Then check if the character ... Read More

Print BST keys in given Range - O(1) Space in C++

sudhir sharma
Updated on 25-Jan-2021 05:28:31

129 Views

In this problem, we are given two values k1 and k2 (k1 < k2), and the root of the binary search tree. Our task is to create a program to Print BST keys in given Range. Problem Description: We will print all the keys of the tree from n1 to n2 in increasing order.Let’s take an example to understand the problem,  Input: k1 = 4, k2 = 12Output: 6, 7, 9Solution ApproachSimple we can solve the problem using inorder traversal but the space complexity there is 0(n) but the need of the hour is to solve in O(1) complexity. So, for this, we will use a ... Read More

Print cells with same rectangular sums in a matrix in C++

sudhir sharma
Updated on 25-Jan-2021 05:28:12

132 Views

In this problem, we are given a matrix mat of size mXn of integer values. Our task is to create a program to Print cells with same rectangular sums in a matrix.Problem description: We will be finding a cell in the matrix in such a way that the sum of sub-matrices that are starting and ending with the cell is equal to the sum of all the remaining elements. For a cell the sum of matrix (a, b) sub-matrix mat[0][0] to mat[a][b] and mat[a][b] to mat[m][n] is equal to the sum of all remaining elements.Let’s take an example to understand the problem, ... Read More

Advertisements