Server Side Programming Articles

Page 876 of 2109

Python - Combine two lists by maintaining duplicates in first list

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

In data analysis using Python, we often need to combine two lists while handling duplicate elements carefully. This article shows how to combine two lists by maintaining all elements from the first list (including duplicates) and adding only unique elements from the second list. Using extend() with Generator Expression This approach preserves the original first list and uses a generator expression to filter unique elements from the second list ? # Given lists first_list = ['A', 'B', 'B', 'X'] second_list = ['B', 'X', 'Z', 'P'] # Create result list starting with first list result = ...

Read More

Python - Convert 1D list to 2D list of variable length

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

A list in Python is normally a 1D list where the elements are listed one after another. But in a 2D list we have lists nested inside the outer list. In this article we will see how to create a 2D list from a given 1D list with variable-length sublists based on specified lengths. Using Slicing with Index Tracking In this approach we will create a for loop to iterate through each required length and use slicing to extract the appropriate elements from the 1D list. We keep track of the current index position and increment it by ...

Read More

Python - Convert a list of lists into tree-like dict

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

Given a nested list, we want to convert it to a dictionary whose elements represent a tree data structure. In this article, we will explore two approaches to transform a list of lists into a hierarchical dictionary structure. Using Simple Iteration and Slicing We reverse the items in each list using slicing and then build the tree structure by checking and adding keys at each level ? Example def create_tree(nested_list): new_tree = {} for list_item in nested_list: current_tree = ...

Read More

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 460 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 721 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
Showing 8751–8760 of 21,090 articles
« Prev 1 874 875 876 877 878 2109 Next »
Advertisements