Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Programming Articles
Page 61 of 2547
Python Program to Square Each Odd Number in a List using List Comprehension
List comprehension is a powerful feature in Python that allows for concise and expressive code when working with lists. It provides a compact way to perform operations on elements and create new lists based on certain conditions. In this tutorial, we'll explore how to square each odd number in a list while keeping even numbers unchanged. Understanding the Problem We need to write a Python program that takes a list of numbers and squares only the odd numbers. For example, given the list [1, 2, 3, 4, 5], the program should return [1, 2, 9, 4, 25], where ...
Read MorePython Program to split string into k sized overlapping strings
Splitting a string into smaller overlapping parts is a common task in text processing, data analysis, and pattern recognition. In this tutorial, we'll explore how to write a Python program that splits a given string into k-sized overlapping strings. Understanding the Problem We need to create overlapping substrings of fixed size k from a given string. For example, if we have the string "Hello" and k=3, we want to generate: "Hel", "ell", "llo". Each substring has length k and starts one position after the previous substring, creating an overlap of k-1 characters. Basic Implementation Here's ...
Read MoreFibonacci Search Visualizer using PyQt5
The Fibonacci Search is an efficient algorithm for searching sorted arrays using Fibonacci numbers. Here, we'll create a visual demonstration of this algorithm using PyQt5 to help understand how it divides the search space. How Fibonacci Search Works The algorithm uses Fibonacci numbers to divide the sorted array into unequal parts, similar to binary search but with golden ratio proportions. It finds two consecutive Fibonacci numbers that are greater than or equal to the array length. Algorithm Steps Step 1: Find the smallest Fibonacci number greater than or equal to the array length. Step 2: ...
Read MoreFernet (Symmetric Encryption) using a Cryptography Module in Python
Symmetric encryption is a cryptographic technique where the same key is used for both encryption and decryption of messages. The Fernet module from Python's cryptography library provides a simple, secure implementation of symmetric encryption using the AES algorithm. How Symmetric Encryption Works Symmetric encryption follows these key steps − Key generation − A secret key is generated and shared between sender and receiver for encrypting and decrypting messages. Encryption − The sender converts plaintext into unreadable ciphertext using the secret key. Transmission − The encrypted ciphertext is ...
Read MoreDifference Between Tensor and Variable in Pytorch
PyTorch is an open-source Python library used for machine learning, computer vision and deep learning. It is an excellent library to build neural networks, conduct complex computations and optimize gradient differentiation. Developed by Facebook's Research Team (FAIR), it gained popularity due to its dynamic computing graphs, allowing it to change graphs in real time. This was revolutionary back in 2016 when models working in real-time just started to emerge. There are two main data structures to understand in PyTorch: Tensor and Variable. Let's explore their differences and evolution. What is a Tensor? A Tensor is used ...
Read MoreDifference between str.capitalize() vs str.title()
In Python, strings are immutable sequences of characters that can be manipulated using various built-in methods. Two commonly used string methods are capitalize() and title(), which both modify the case of characters but work differently. str.capitalize() The capitalize() method converts only the first character of the entire string to uppercase and makes all remaining characters lowercase. It treats the entire string as a single unit, regardless of spaces or word boundaries. Syntax str_name.capitalize() Here, str_name is the input string. The method takes no arguments and returns a new string. Example ...
Read MoreDifference between Shallow Copy vs Deep Copy in Pandas Dataframe
One of the most useful data structures in Pandas is the DataFrame — a 2-dimensional table-like structure containing rows and columns to store data. Understanding the difference between shallow and deep copies is crucial when manipulating DataFrames, as it affects how changes propagate between original and copied objects. What is Shallow Copy? A shallow copy creates a new DataFrame object that references the original data. The copied DataFrame points to the same memory location as the original DataFrame. Any modifications to the underlying data will affect both the original and shallow copy. Syntax df_shallow = ...
Read MoreSort the string as per the ASCII values of the characters
ASCII (American Standard Code for Information Interchange) assigns unique numeric values to characters. In Python, we can sort strings based on these ASCII values to arrange characters in ascending order. Problem Statement Given a string, we need to sort its characters according to their ASCII values in increasing order. Let's understand this with examples ? Example 1 Input: "$%7wjk()" Output: "$%()7jkw" The ASCII values are ? $ → 36 % → 37 ( → 40 ) → 41 7 → 55 j → 106 k → 107 w → 119 Example ...
Read MoreDifference between Shallow and Deep Copy of a Class
A class is a blueprint that defines objects' attributes (data) and behaviors (methods). When working with class instances, you often need to create copies. Python provides two types of copying: shallow copy and deep copy, each with different behaviors regarding nested objects. Shallow Copy Shallow copy creates a new object but stores references to the original elements. Instead of duplicating nested objects, it copies their references. This means modifications to nested objects affect both the original and the copy. Shallow copy is performed using copy.copy() method from the copy module. Deep Copy Deep copy creates ...
Read MoreDifference Between Queue and Collestions in Python
In Python, a queue is a data structure that follows FIFO (First In First Out) principle, where elements are processed in the exact order they were added. Python provides two main approaches for queue implementation: queue.Queue and collections.deque, each with distinct characteristics suited for different scenarios. Key Differences Category queue.Queue collections.deque Thread Safety Thread-safe with built-in synchronization for multithreading Not thread-safe by default, requires external synchronization Functionality Designed specifically for FIFO operations with put() and get() methods Double-ended queue supporting both FIFO and LIFO with methods like append(), pop(), popleft() ...
Read More