Programming Articles

Page 895 of 2547

Python - Check if k occurs atleast n times in a list

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

When analyzing data in Python lists, you often need to check if a specific element appears at least N times. For example, determining if the number 5 appears at least 3 times in a list. This article demonstrates three efficient approaches to solve this problem. Using Manual Counting The most straightforward approach is to iterate through the list and count occurrences of the target element ? data = [1, 3, 5, 5, 4, 5] print("Given list:", data) # Element to be checked elem = 5 # Minimum required occurrences n = 3 count = ...

Read More

Pygorithm module in Python

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

The Pygorithm module is an educational Python library containing implementations of various algorithms and data structures. Its primary purpose is to provide ready-to-use algorithm code for learning and practical applications in data processing. Installation Install Pygorithm using pip ? pip install pygorithm Finding Available Data Structures After installation, you can explore the various data structures included in the package ? from pygorithm import data_structures help(data_structures) The output shows all available data structures ? Help on package pygorithm.data_structures in pygorithm: NAME pygorithm.data_structures - Collection ...

Read More

Oracle Database Connection in Python

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

Python can connect to Oracle using a python package called cx_Oracle. Oracle is one of the famous and widely used databases and Python's data processing features are leveraged well using this connectivity. In this article we will see how we can connect to Oracle database and query the DB. Installing cx_Oracle We can use the below command to install the python package which can be used for establishing the connectivity ? pip install cx_Oracle Connecting to Oracle Using this module we can connect to an Oracle database which is accessible through the Oracle ...

Read More

The netrc file processing using Python

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

The netrc class in Python is used to read data from the .netrc file present in Unix systems in the user's home directory. These are hidden files containing user's login credential details. This is helpful for tools like ftp, curl etc. to successfully read the .netrc file and use it for authentication. What is a .netrc File? A .netrc file stores login credentials for remote hosts in a standardized format. Each entry contains a machine name, login username, and password. The file format looks like ? machine example.com login myusername password mypassword machine ftp.example.com login ...

Read More

Encode and decode XDR data using Python xdrlib

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

The External Data Representation (XDR) is a standard data serialization format used for transporting data between different systems. Python's xdrlib module provides encoders and decoders for XDR format, making it useful for creating and transferring complex data structures across networks. XDR provides a service associated with the OSI Presentation Layer and ensures consistent data representation regardless of the underlying system architecture. Basic XDR Packing and Unpacking The following example demonstrates how to pack and unpack data using the xdrlib module ? import xdrlib # Create a packer object packer = xdrlib.Packer() print("Packer type:", type(packer)) ...

Read More

Encode and decode uuencode files using Python

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

The uuencode module in Python provides functions to encode and decode files using the Unix uuencoding format. This encoding method converts binary data into ASCII text, making it safe for transmission over text-based protocols. Understanding Uuencoding Uuencoding (Unix-to-Unix encoding) transforms binary files into printable ASCII characters. The encoded output includes a header with file permissions and name, followed by encoded data lines. Encoding a File The uu.encode() function converts a binary file into uuencoded format ? Syntax uu.encode(in_file, out_file, name=None, mode=None) Example import uu import io # Create ...

Read More

Encode and decode MIME quoted-printable data using Python

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

When working with emails and web data, we often encounter non-ASCII characters that need special encoding. MIME quoted-printable encoding helps transmit such data safely over protocols that only support ASCII characters. Python provides built-in modules to handle this encoding and decoding efficiently. Using the email Package The email package includes modules for handling MIME encoding. Here's how to create a quoted-printable encoded message ? import email.mime.nonmultipart import email.charset # Create MIME message with UTF-8 charset msg = email.mime.nonmultipart.MIMENonMultipart('text', 'plain', charset='utf-8') # Construct charset with quoted-printable encoding cs = email.charset.Charset('utf-8') cs.body_encoding = email.charset.QP # ...

Read More

Python - Convert list of nested dictionary into Pandas Dataframe

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

Many times Python will receive data from various sources which can be in different formats like CSV, JSON etc which can be converted to Python lists or dictionaries. But to apply calculations or analysis using packages like pandas, we need to convert this data into DataFrames. In this article we will see how we can convert a given Python list whose elements are nested dictionaries, into a pandas DataFrame. Basic Approach We first take the list of nested dictionary and extract the rows of data from it. Then we create another for loop to append the rows into ...

Read More

Get unique values from a list in Python

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

A list in Python is a collection of items placed within [] which may contain duplicate values. In this article, we will explore different methods to extract only the unique values from a list while preserving or modifying the original order. Using append() with Manual Checking This approach creates a new empty list and appends elements only if they don't already exist. We use a for loop with not in condition to check for duplicates ? Example def get_unique_values(original_list): # Initialize an empty list unique_list = [] ...

Read More

Get last element of each sublist in Python

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

A list in Python can also contain lists inside it as elements. These nested lists are called sublists. In this article we will solve the challenge of retrieving only the last element of each sublist in a given list. Using for Loop It is a very simple approach in which we loop through the sublists fetching the item at index -1 in them. A for loop is used for this purpose as shown below ? sublists = [['Mon', 1], ['Tue', 'Wed', "Fri"], [12, 3, 7]] print("Given List:") print(sublists) print("Last Items from sublists:") for item in ...

Read More
Showing 8941–8950 of 25,466 articles
« Prev 1 893 894 895 896 897 2547 Next »
Advertisements