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 More
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 More
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 More
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 More
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 More
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 More
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
Python's key data structures are lists and tuples. Tuples are immutable collections where elements cannot be changed once set, while lists can be modified after initialization. When dealing with data that needs to be grouped together, a for loop is commonly used to create lists of tuples. This tutorial demonstrates creating a list of tuples using a for loop, simplifying repetitive data organization tasks. Syntax for variable in iterable: # loop code Basic Operations on Tuples Creating and Accessing Tuples # Initializing tuples my_tuple = (1, 2, "Hello", ... Read More
A dictionary of tuples in Python combines the key-value structure of dictionaries with the immutable, ordered nature of tuples. This creates an efficient way to store multiple related values for each key, such as student information, product details, or coordinates. Syntax The basic syntax for creating a dictionary of tuples is ? dictionary_name = { key1: (value1_1, value1_2, ...), key2: (value2_1, value2_2, ...), key3: (value3_1, value3_2, ...) } Basic Example Let's create a dictionary storing student names and their test scores ... Read More
An acronym is an abbreviated version of a phrase formed by taking the first character of each word. For example, "CPU" is an acronym for "Central Processing Unit". In this article, we will learn different methods to create acronyms from words using Python. Example Scenario Input: "Automatic Teller Machine" Output: "ATM" Explanation: The acronym is created by taking the first character of each word: A-T-M. Algorithm to Create Acronyms The following steps create acronyms from words using Python − Split the input string into individual words using split() ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Economics & Finance