Chrono library in C++

Aman Kumar
Updated on 15-May-2025 15:38:25

776 Views

; is a C++ header that is included in C++11 or later versions and states the collection of types and functions to work with time. It is a part of the C++ Standard Template Library (STL). Why We Need It provides a precision-neutral concept by separating the durations and points of time. So, if we want to improve time over precision, we can use this library. provides three primary types of clocks: system_clock, steady_clock, and high_resolution_clock. These clocks are used to measure time in various ways: system_clock: It represents the system-wide real-time wall ... Read More

C++ Program to Count Inversion in an Array

Aman Kumar
Updated on 15-May-2025 15:36:22

825 Views

The inverse count of an array indicates how far or how close the array is from being sorted. If the array is already sorted, then the inverse count is zero, but if the array is sorted in reverse order, then the inverse count is maximum. Here we have given an integer array of size n and need to find the inversions in the array. If two array elements arr[i] and arr[j] form an inversion if arr[i]>arr[j] and i

C++ Program to Implement a Binary Search Tree using Linked Lists

Aman Kumar
Updated on 15-May-2025 15:32:02

3K+ Views

A linked list is a linear data structure in which we store a sequence of elements, where each element is called a node that contains data and a pointer (or link) to the next element in the sequence. In this C++ article, we will implement a Binary search tree using a linked list. Binary Search Tree A binary search tree is a hierarchical data structure that is constructed by nodes. Each node contains a value and its reference to the left and right child nodes. So the value in the left child node is less than the parent node, and ... Read More

How to list non-hidden files and directories in windows using Python?

Sarika Singh
Updated on 15-May-2025 15:26:41

2K+ Views

Listing files and directories using Python is a common task in many applications, from file management tools to automated scripts. However, when we are working on the Windows Operating System, the hidden files and folders are marked using specific file attributes, which can clutter the output if not handled properly. Unlike Unix-based systems, where hidden files typically start with a dot such as .hidden) whereas Windows uses metadata to mark files as hidden. In this article, we'll explore several methods to list only non-hidden files and directories. Basic Filtering by Name Prefix This is the basic Filtering method, which checks ... Read More

How expensive are Python dictionaries to handle?

Sindhura Repala
Updated on 15-May-2025 15:15:16

246 Views

Python dictionaries are very difficult to handle data. They use a special system called hashing, which allows quick access to information. This specifies the cost of different operations: Time Complexities of Dictionary Operations Python dictionaries are usually fast because they use hashing to find and store data. The time complexity of dictionary operations in Python depends on the size of the dictionary and the operations performed. Here are some of the common dictionary operations - ... Read More

What are the allowed characters in Python function names?

Sarika Singh
Updated on 15-May-2025 14:20:17

2K+ Views

In Python, function names follow specific rules. A valid function name can only contain certain characters, and it must follow the naming conventions defined in the Python language syntax. Using the correct characters ensures that your code runs without syntax errors and stays readable. Allowed Characters in Function Names Python function names can consist of the following characters - Letters (A–Z, a–z) Digits (0–9) — but not at the beginning Underscores (_) — often used to separate words Function names must follow these rules - Must start with a letter or underscore Cannot start with a digit ... Read More

What is the difference between 'except Exception as e' and 'except Exception, e' in Python?

Sarika Singh
Updated on 15-May-2025 14:07:20

1K+ Views

You can handle errors in Python using the try and except blocks. Sometimes, we also want to store the actual exception in a variable to print it or inspect it. This is done using the as keyword in modern Python. But if you have seen older code, you might find except Exception e or even except Exception, e being used. In this article, we will explore the difference between these syntaxes, understand why older ones no longer work in Python 3, and learn the best practices for clean exception handling. Understanding Basic Exception Handling Python provides try-except blocks to catch ... Read More

How to raise Python exception from a C extension?

Rajendra Dharmkar
Updated on 15-May-2025 14:00:10

260 Views

When writing a C extension for Python, you might need to raise an exception if something goes wrong in your C code. Python provides a special C API that helps you to raise errors in a way that works just like regular Python exceptions.This is helpful because even if your code is written in C for better performance, users can still handle errors using Python's normal try...except blocks. It makes your extension feel just like any other Python module.Using Python C API to Raise ExceptionsIn C extensions for Python, you can raise exceptions using the Python C API functions like ... Read More

What is the use of "assert" statement in Python?

Sarika Singh
Updated on 15-May-2025 13:57:00

380 Views

In Python, the assert statement is used for debugging purposes. It tests whether a condition in your program returns True, and if not, it raises an AssertionError. This helps you catch bugs early by verifying that specific conditions are met while the code is executing. Understanding the Assert Statement The assert statement is used to verify that a given condition is true during execution. If the condition evaluates to False, the program stops and throws an AssertionError, optionally displaying a message. Example: Assertion without a message In this example, we are asserting that 5 is greater than 3, which is ... Read More

How to catch KeyError Exception in Python?

Sarika Singh
Updated on 15-May-2025 13:54:35

962 Views

In Python, a KeyError exception occurs when a dictionary key that does not exist is accessed. This can be avoided by using proper error handling with the try and except blocks, which can catch the error and allow the program to continue running. Understanding KeyError in Python A KeyError is raised when you try to access a key that doesn't exist in a dictionary. It is one of the built-in exceptions that can be handled by Python's try and except blocks. Example: Accessing a non-existent key In this example, we are attempting to access a key that does not exist ... Read More

Advertisements