How to recursively iterate a nested Python dictionary?

Niharikaa Aitam
Updated on 07-Jun-2025 22:42:30

10K+ Views

A Dictionary in Python is a mutable, unordered collection of data in a key-value format. A dictionary can also contain another dictionary as a value and this is known as a Nested Dictionary or a dictionary within a dictionary. When working with this type of data structure, it’s often important to go through each key-value pair at every level. In this article, we will explore how to recursively iterate through a nested Python dictionary using a function-based approach. Syntax to iterate through a Dictionary recursively Following is a sample syntax for recursively iterating through a nested dictionary - def recursive_iter(d): ... Read More

What is the simplest way to SSH using Python?

Niharikaa Aitam
Updated on 07-Jun-2025 22:28:13

6K+ Views

SSH is referred as secure shell which is useful to remotely manage computers in a secure manner. To connect to a server, we typically use PuTTy, MobaXTerm or the command-line ssh application. Every Unix, Linux and Mac server includes SSH as standard equipment and it is usable in every data centre. SSH connections have made it feasible for secure remote access to resources, remote command execution, the transmission of software patches and updates and other administrative or management tasks. SSH is used in systems administration and file transfer software as well as to handle routers, server hardware, virtualization platforms and ... Read More

Are Python Exceptions runtime errors?

Sarika Singh
Updated on 07-Jun-2025 22:13:54

977 Views

Are Python Exceptions Runtime Errors? Yes, Python exceptions are considered runtime errors. Most exceptions occur during runtime.Exceptions in Python are errors that occur when there is an abnormal scenario during the execution of a program, which terminates the execution abruptly, interrupting its normal flow. Examples of exceptions are ZeroDivisionError, IndexError,  ValueError, etc..Whereas, errors in Python are detected before the execution of the program, they include syntactical errors and other violations of the program rules. Examples of errors are SyntaxError,  IndentationError,  etc.  Exceptions are Raised at Runtime Exceptions occur when the execution of the program is interrupted because of issues like logical ... Read More

How to catch FloatingPointError Exception in Python?

Sarika Singh
Updated on 07-Jun-2025 20:25:51

2K+ Views

Catching FloatingPointError Exception in PythonFloatingPointError in Python is an exception that occurs when there is an error in floating-point calculations. By default, Python does not raise this error for basic operations like dividing by zero; instead, it returns inf or nan. To catch this error, you need to enable it explicitly using the numpy module. In this article, you will learn how to catch a FloatingPointError by enabling it through NumPy settings and handling it using a try-except block. When Does FloatingPointError Occur? FloatingPointError can occur in cases like - Divide by zero in floating-point calculations (if enabled) ... Read More

How to catch ImportError Exception in Python?

Sarika Singh
Updated on 07-Jun-2025 19:42:48

4K+ Views

The ImportError exception in Python is raised when the interpreter cannot find or load a module that is being imported using the import statement.  Catching the ImportError ExceptionLike any other exception, we can catch the ImportError exception using the try-except blocks. In this article, we discuss various scenarios where the ImportError exception occurs, with examples, and catch the generated exception using the try-except blocks in each scenario.When Does ImportError Occur?The ImportError generally occurs in the following cases -Trying to import a module that doesn't exist.Misspelling the module name.Trying to import a function or class that is not available in the specified module.Example: Importing a ... Read More

How to catch ValueError using Exception in Python?

Sarika Singh
Updated on 07-Jun-2025 19:10:08

364 Views

While passing arguments to a Python function, if the datatype of the given values is different from the function parameters, a TypeError is raised. But if the type of the argument is accurate and its value is inappropriate, a ValueError exception is raised In this article, you will learn how to catch ValueError exceptions using the general Exception class, which can catch all built-in exceptions, including ValueError. The ValueError exception commonly occurs when - You convert a string to an integer or float, but the string is not valid You pass an invalid value ... Read More

How to catch ZeroDivisionError Exception in Python?

Sarika Singh
Updated on 07-Jun-2025 18:13:43

587 Views

ZeroDivisionError Exception in Python The ZeroDivisionError is raised in Python when a number is divided by zero. Since dividing by zero is mathematically undefined, Python throws this error. In this article, you will learn how to catch and handle ZeroDivisionError using the try-except block. Usually, when an exception occurs, the program will be terminated abruptly, leaving the statements after the exception unexecuted. By handling this exception, the execution of the program continues even after the ZeroDivisionError exception (an invalid division attempt). The ZeroDivisionError generally occurs in the following cases - Dividing any number by zero using / ... Read More

How to catch StandardError Exception in Python?\\\\

Sarika Singh
Updated on 07-Jun-2025 17:48:24

525 Views

StandardError in Python 2In Python 2, StandardError was a built-in exception class that is a base class for all built-in exceptions except for SystemExit, KeyboardInterrupt, and GeneratorExit. Using this class, we were able to catch the most common runtime errors in a single except block. However, since Python 3, the StandardError class has been deprecated, and now all built-in exceptions directly inherit from the Exception class. If you are using Python 3, you should catch exceptions using Exception instead of StandardError. Example Following is a basic example of raising the StandardError exception in Python 2 - try: value ... Read More

How to catch StopIteration Exception in Python?

Sarika Singh
Updated on 07-Jun-2025 17:15:16

1K+ Views

StopIteration Exception in Python  The StopIteration exception in Python is raised to indicate that there are no more items left in an iterator to retrieve. It occurs when a call to the next() or,   __next__() reaches the end of an iterable. In this article, you will learn how and when StopIteration is raised, and how to catch and handle it using try-except blocks. When Does StopIteration Occur? When can retrieve the contents of an Iterator object,  using the Python built-in function next() or the __next__() method (of the iterator object). The next() function internally calls the _next__() method. These methods return the ... Read More

How can we highlight the selected tab of a JTabbedPane in Java?

Alshifa Hasnain
Updated on 06-Jun-2025 19:41:24

841 Views

In this article, we will learn to highlight the selected tab of a JTabbedPane in Java. JTabbedPane is a common Swing component that is used to organize content into multiple tabs, while highlighting a selected tab will improve the GUI and make the interface interactive. What is a JTabbedPane? A JTabbedPane is a subclass of the JComponent class, and it can provide easy access to more than one panel. Each tab is associated with a single component that can be displayed when the tab is selected. A JTabbedPane can generate a ChangeListener interface when a tab is selected. What do ... Read More

Advertisements