Server Side Programming Articles

Page 11 of 2110

Multi-dimensional lists in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 10K+ Views

Lists are a very widely used data structure in Python. They contain a list of elements separated by commas. 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 Lists In the below program we create a multidimensional list of 4 columns and 3 rows using nested for loops ? multlist = [[0 for columns in range(4)] for rows in range(3)] print(multlist) The output of the above code is ...

Read More

Launching parallel tasks in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 438 Views

Parallel processing allows Python programs to break work into independent subprograms that can run simultaneously. This improves performance by utilizing multiple CPU cores and reducing overall execution time. Using multiprocessing Module The multiprocessing module creates child processes that run independently from the main process. Each process has its own memory space and can execute code in parallel ? Basic Process Creation import multiprocessing import time class WorkerProcess(multiprocessing.Process): def __init__(self, process_id): super(WorkerProcess, self).__init__() self.process_id = ...

Read More

Importing Data in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 17K+ Views

When working with data analysis in Python, importing data from external sources is a fundamental skill. Python provides several powerful modules for reading different file formats including CSV, Excel, and databases. Let's explore the most common approaches for importing data. Importing CSV Files The built-in csv module allows us to read CSV files row by row using a specified delimiter. We open the file in read mode and iterate through each row ? import csv import io # Sample CSV data csv_data = """customerID, gender, Contract, PaperlessBilling, Churn 7590-VHVEG, Female, Month-to-month, Yes, No 5575-GNVDE, Male, ...

Read More

Catching the ball game using Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 2K+ Views

Python's tkinter library makes it easy to create interactive games. In this article, we'll build a ball catching game where a ball falls from random positions and the player moves a paddle to catch it using left and right buttons. Game Overview The game consists of a falling blue ball and a green paddle at the bottom. Players use two buttons to move the paddle left or right to catch the ball. Each successful catch scores 5 points, and missing a ball ends the game. Approach The game development follows these key steps: Step ...

Read More

Binding function in Python Tkinter

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 2K+ Views

In Python, Tkinter is a GUI library used for desktop application development. Binding functions is a crucial concept that connects events (like keyboard presses or mouse clicks) to specific functions, allowing your application to respond to user interactions. Binding Keyboard Events You can bind keyboard events to functions using the bind() method. When a key is pressed, the bound function executes automatically ? Example from tkinter import * # Function to handle key press events def press_any_key(event): value = event.char print(f'{value} - A button is pressed') ...

Read More

Associating a single value with all list items in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 405 Views

We may have a need to associate a given value with each and every element of a list. For example − there are the names of the days and we want to attach the word "day" as a suffix to them. Such scenarios can be handled in the following ways. Using itertools.repeat We can use the repeat method from the 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 ? from itertools import repeat days = ['Sun', 'Mon', 'Tues'] ...

Read More

Standard errno system symbols in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 561 Views

Python provides built-in error handling through the errno module, which contains standard system error codes and messages. These error codes help identify specific types of errors that can occur during program execution. Listing All Standard Error Codes The errno module contains predefined error numbers and their corresponding symbolic names. We can list all available error codes using the errorcode dictionary along with os.strerror() to get human-readable descriptions ? import errno import os print("Error Code : Description") print("-" * 30) for error_code in sorted(errno.errorcode): print(f"{error_code} : {os.strerror(error_code)}") Error ...

Read More

Python Get the numeric prefix of given string

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 451 Views

Sometimes we need to extract the numeric prefix from a string that contains numbers at the beginning. Python provides several approaches to extract only the numeric part from the start of a string. Using takewhile() with isdigit() The isdigit() method checks if each character is a digit. Combined with takewhile() from itertools, we can extract consecutive digits from the beginning ? from itertools import takewhile # Given string string_data = "347Hello" print("Given string:", string_data) # Using takewhile with isdigit result = ''.join(takewhile(str.isdigit, string_data)) print("Numeric prefix from the string:", result) The output ...

Read More

Python Get a list as input from user

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 10K+ Views

In this article, we will see how to ask the user to enter elements of a list and create the list with those entered values. Python provides several approaches to collect user input and build lists dynamically. Using Loop with input() and append() The most straightforward approach is to ask for the number of elements first, then collect each element individually using a loop ? numbers = [] # Input number of elements n = int(input("Enter number of elements in the list : ")) # iterating till the range for i in range(0, n): ...

Read More

Python Generate successive element difference list

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 515 Views

Finding the difference between successive elements in a list is a common operation in Python. This article explores three efficient methods to calculate consecutive element differences using list comprehension, list slicing, and the operator module. Using List Comprehension with Index The most straightforward approach uses list comprehension with index positions to access consecutive elements ? numbers = [12, 14, 78, 24, 24] # Given list print("Given list:", numbers) # Using index positions with list comprehension differences = [numbers[i + 1] - numbers[i] for i in range(len(numbers) - 1)] # Print result print("Successive differences:", ...

Read More
Showing 101–110 of 21,091 articles
« Prev 1 9 10 11 12 13 2110 Next »
Advertisements