Server Side Programming Articles

Page 647 of 2109

How to recursively iterate a nested Python dictionary?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 11K+ Views

A Dictionary in Python is a mutable collection of data in a key-value format. A dictionary can also contain another dictionary as a value, creating a Nested Dictionary or a dictionary within a dictionary. When working with nested data structures, you often need to access each key-value pair at every level using recursive iteration. In this article, we will explore how to recursively iterate through a nested Python dictionary using different approaches. Basic Syntax Here's the basic syntax for recursively iterating through a nested dictionary ? def recursive_iter(d): for key, value ...

Read More

How to match a non-whitespace character in Python using Regular Expression?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 4K+ Views

A non-whitespace character is any character that is not a space, tab i.e., \t, newline i.e., or carriage return \r. Examples of non-whitespace characters include letters, digits, punctuation and special symbols. In Python, Regular Expressions (RegEx) are used to match patterns in input strings. The re module in Python provides different methods to use regular expressions. This module helps developers perform search operations, validations, filtering and much more based on string patterns. To match a non-whitespace character in Python we can use the special character class \S inside a raw string with any re module method. In ...

Read More

How to match non-word characters in Python using Regular Expression?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 2K+ Views

A Non-word character is any type of character that is not a letter, digit, or underscore, i.e., anything other than [a-z, A-Z, 0-9_]. Examples of non-word characters are symbols, punctuation marks, spaces, tabs, and other special characters. In Python, Regular Expressions (RegEx) are used to match the patterns in the given input strings. The re module in Python provides different methods to use the regular expressions. This module helps the developers to perform search operations, validations, filtering and much more, based on string patterns. To match a non-word character in Python, we can use the special ...

Read More

How to match a word in python using Regular Expression?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 5K+ Views

In Python, Regular Expressions (RegEx) are used to match patterns in the given input strings. The re module in Python provides different methods to use the regular expressions. This module helps the developers to perform search operations, validations, filtering, and much more based on string patterns. In this article, we will explore different ways to match a word in Python using the re module. Match a Specific Word using re.search() In Python, the re.search() method is used to search for a pattern within a given string. If the pattern is found, then it returns a match object ...

Read More

How to merge two Python dictionaries in a single expression?

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 24-Mar-2026 388 Views

In Python, a Dictionary is an unordered and mutable data structure which stores data as key-value pairs. In some cases, we may need to merge two dictionaries into a single dictionary using a single expression. Python provides several methods to accomplish this task efficiently. Using | Merge Operator (Python 3.9+) The | merge operator is the most modern and readable way to merge dictionaries in a single expression. It returns a new dictionary containing all key-value pairs from both dictionaries. If both dictionaries have the same key, the value from the right-side dictionary takes precedence ? ...

Read More

How to change any data type into a string in Python?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 374 Views

In Python, converting different data types into strings is a common requirement when we want to display or store information in text format. The built-in str() function is the primary method for this conversion, accepting any Python object and returning its string representation. Syntax str(object) Where object is any valid Python object, such as int, float, bool, list, etc. Converting Integer to String An integer can be converted into a string using the str() function. This conversion is useful when concatenating numbers with strings ? num = 42 string_num = str(num) ...

Read More

What are different data conversion methods in Python?

Sarika Singh
Sarika Singh
Updated on 24-Mar-2026 1K+ Views

Data conversion in Python refers to changing the data type of a value to another data type. Python supports two different types of data conversion: Implicit conversion and Explicit conversion. Implicit Conversion is performed automatically by the Python interpreter. Explicit Conversion is manually done by the programmer using built-in functions. Implicit Conversion Python automatically converts one data type to another to avoid data loss during operations. The smaller data type is converted to a higher data type ? Example The following example shows how Python ...

Read More

How to print a string two times with single statement in Python?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 418 Views

When developing Python applications, you may need to repeat or duplicate a string for display or formatting purposes. Python provides several ways to print a string twice with a single statement. There are different approaches to print a string twice with a single statement in Python: Using Multiplication Operator Using the Concatenation Operator Using the format() Method Using f-string Using join() Method with a List Using List Unpacking Using ...

Read More

How to divide a string by line break or period with Python regular expressions?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 24-Mar-2026 432 Views

When working with text processing in Python, you often need to split strings by multiple delimiters like periods and line breaks. Python's regular expressions module re provides powerful pattern matching for this purpose. Using re.findall() to Split by Period and Line Break The re.findall() function extracts all substrings that match a given pattern. Here's how to split a string by periods and line breaks − import re s = """Hi. It's nice meeting you. My name is Jason.""" result = re.findall(r'[^\s\.][^\.]+', s) print(result) ['Hi', "It's nice meeting you", 'My name is ...

Read More

How can I match the start and end in Python\'s regex?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 2K+ Views

In Python, the re module is used to work with regular expressions. In some cases, we need to check whether a string starts or ends with a specific pattern, and then we need to use special regex characters called anchors. Following are the anchors used in regular expressions − ^ − This anchor matches the beginning of a string. $ − This anchor matches the end of a string. Python Regex Methods The following methods from the re module are commonly used to apply start and end ...

Read More
Showing 6461–6470 of 21,090 articles
« Prev 1 645 646 647 648 649 2109 Next »
Advertisements