Found 26504 Articles for Server Side Programming

Multi-dimensional lists in Python

Pradeep Elance
Updated on 10-Jul-2020 11:19:39

9K+ Views

Lists are a very widely use data structure in python. They contain a list of elements separated by comma. But sometimes lists can also contain lists within them. These are called nested lists or multidimensional lists. In this article we will see how to create and access elements in a multidimensional list.Creating Multi-dimensional listIn the below program we create a multidimensional list of 4 columns and 3 rows using nested for loops.Example Live Demomultlist = [[0 for columns in range(4)] for rows in range(3)] print(multlist)OutputRunning the above code gives us the following result −[[0, 0, 0, 0], [0, 0, 0, 0], ... Read More

MongoDB and Python

Pradeep Elance
Updated on 10-Jul-2020 11:17:08

691 Views

MongoDB is a widely used document database which is also a form of NoSQL DB. Python can interact with MongoDB through some python modules and create and manipulate data inside Mongo DB. In this article we will learn to do that. But MongoDB should already be available in your system before python can connect to it and run. To setup MongoDB in your system please visit our  MongoDB tutorial here..Install pymongoTo interact with MongoDB we need the module names pymongo. Install it in your python environment using the below command.pip install pymogoCheck the Existing DBsWe now use this python module ... Read More

Launching parallel tasks in Python

Pradeep Elance
Updated on 10-Jul-2020 11:15:01

387 Views

If a Python program can be broken into subprograms who is processing do not depend on each other, then each of the subprogram can be run in parallel when the overall program is being run. This concept is known as parallel processing in Python.With multiprocessingThis module can be used to create many child processes of a main process which can run in parallel. In the below program we initialize a process and then use the run method to run the multiple sub-processes. We can see different sub processes in the print statement by using the process id. We also use ... Read More

Interpreting stat() results using Python

Pradeep Elance
Updated on 10-Jul-2020 11:12:28

437 Views

The stat() method is part of OS module which describes various OS related operations on files and directories. For example, if we want to know various user defined flags for a file or size of the file in bytes.Functions in os.stat() moduleBelow is a list of some sample functions available in stat() and their meaning.st_size − It represents the size of the file in bytes.st_atime − It represents the time of most recent access. It is expressed in seconds.st_ctime − It represents the time of most recent metadata change on Unix and creation time on Windows. It is expressed in seconds.st_blocks ... Read More

Importing Data in Python

Pradeep Elance
Updated on 10-Jul-2020 11:10:27

17K+ Views

When running python programs, we need to use datasets for data analysis. Python has various modules which help us in importing the external data in various file formats to a python program. In this example we will see how to import data of various formats to a python program.Import csv fileThe csv module enables us to read each of the row in the file using a comma as a delimiter. We first open the file in read only mode and then assign the delimiter. Finally use a for loop to read each row from the csv file.Exampleimport csv with ... Read More

GET and POST requests using Python Programming

Pradeep Elance
Updated on 10-Jul-2020 10:59:24

3K+ Views

Python can be used to access webpages as well as post content to the webpages. There are various modules like httplib, urllib, httplib2 etc but the requests module is simplest and can be used to write simpler yet powerful programs involving GET and POST methods.GET methodThe GET method is part of the python requests module which is used to obtain data from a web URL. In the below example we reach out to our own website and find out various responses through the get method. We get the encoding, response time and also the header and part of the body.Example Live ... Read More

Catching the ball game using Python

Pradeep Elance
Updated on 10-Jul-2020 09:55:19

2K+ Views

Python can also be used to create computer games. In this article we will see how the ball catching game can be created using python. In this game a ball keeps falling from the top of a canvas window and a bar is present at the bottom of the window. Two buttons are provided to move the bar in the left and right direction. Using mouse button presss we move the bar at the bottom to catch the falling ball. At different times the ball falls from different positions .ApproachThe approach to build the game is described in the following ... Read More

Calculate difference between adjacent elements in given list using Python

Yaswanth Varma
Updated on 24-Jul-2025 18:06:26

1K+ Views

Difference Between Adjacent List Elements  The given task is to calculate the difference between the adjacent elements in the given list using Python, i.e, we need to subtract the current element from the next element and repeat this for each element in the list (except the last one). Scenario Following is an example scenario: Input: [10, 15, 12, 18] Output: [5, -3, 6] Explanation: Difference between 15 and 10: 15 - 10 = 5 Difference between 12 and 15: 12 - 15 = -3 Difference between 18 and 12: 18 - 12 = 6 Using List ... Read More

Binding function in Python Tkinter

Pradeep Elance
Updated on 10-Jul-2020 09:47:21

2K+ Views

In python tkinter is a GUI library that can be used for various GUI programming. Such applications are useful to build desktop applications. In this article we will see one aspect of the GUI programming called Binding functions. This is about binding events to functions and methods so that when the event occurs that specific function is executed.Binding keyboard eventIn the below example we bind the press of any key from the keyboard with a function that gets executed. Once the Tkinter GUI window is open, we can press any key in the keyboard and we get a message that ... Read More

Associating a single value with all list items in Python

Pradeep Elance
Updated on 10-Jul-2020 09:44:13

348 Views

We may have a need to associate a given value with each and every element of a list. For example − there are the name of the days and we want to attach the word day as a suffix in them. Such scenarios can be handled in the following ways.With itertools.repeatWe can use the repeat method from itertools module so that the same value is used again and again when paired with the values from the given list using the zip function.Example Live Demofrom itertools import repeat listA = ['Sun', 'Mon', 'Tues'] val = 'day' print ("The Given list : ... Read More

Advertisements