Programming Articles

Page 37 of 2544

How do I un-escape a backslash-escaped string in Python?

Yaswanth Varma
Yaswanth Varma
Updated on 17-Jun-2025 11K+ Views

In Python, the backslash-escaped string contains the characters that are followed by backslash(\), which are used as escape characters. For example, represents the literal characters "" and "n" (not a new line). In some scenarios, we need to unescape such a string, i.e, convert these sequences back to their intended special characters or read them as normal text. Python provides several ways to achieve this. In this article, we will explore how to un-escape a backslash-escaped string. Using Python .decode() Method The Python decode() method is used to decode the string using the codec ...

Read More

How do I wrap a string in a file in Python?

Yaswanth Varma
Yaswanth Varma
Updated on 17-Jun-2025 3K+ Views

Wrapping the string means formatting or breaking the string so that it fits within the specified width. It is useful when writing the content to the file, such as logs or console-like outputs. Python provides various ways to achieve string wrapping before writing it to the file using the built-in methods. In this article, we are going to learn how to wrap a string in a file in Python. Using Python textwrap.wrap() Method The textwrap.wrap() method is used to wrap a single paragraph of text. so that every line is at most a specified length. It accepts a text ...

Read More

How to Convert String to JSON using Python?

Yaswanth Varma
Yaswanth Varma
Updated on 17-Jun-2025 3K+ Views

In this article, we are going to learn how to convert a string to JSON in Python. JSON is a lightweight data interchange format that is used to read and write, and store data. Usually, we receive JSON data in the form of a string. To process it using a Python program, we need to convert the JSON string into an object, which can be stored in Python dictionaries and lists. This conversion can be done by using functions provided by the Python JSON module. Using Python json.loads() Function The Python json.loads() function is used to convert the JSON-formatted ...

Read More

How to compare pointers in C/C++?

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 17-Jun-2025 8K+ Views

The pointers can be directly compared using relational operators. In this article, we will learn about the comparisons of the pointers with the help of examples. Pointers Comparison in C and C++ In C/C++, we can directly compare the pointers using relational operators (==, !=, , =). These operators are used to compare two variables, values, or pointers. It returns a Boolean true value when the comparison is correct otherwise, it is false. The core syntaxes of C and C++ pointers are similar such as declaration, dereferencing, and pointer arithmetic. All of these are identical in behavior and still use ...

Read More

Can we use function on left side of an expression in C and C++?

Revathi Satya Kondra
Revathi Satya Kondra
Updated on 17-Jun-2025 465 Views

In C, you cannot use a function call on the left side of an assignment if it returns a value because function calls return non-assignable values. For example, function_name() = value; However, if the function returns a pointer, you can dereference it to assign a value. For example, *function_name() = value; In C++, the same rule applies. You can use the returned reference/pointer on the left side to modify the original variable which is valid only if it returns a reference. function_name() = value; Note: References allow direct access to variables, and pointers allow indirect access via dereferencing. ...

Read More

C++ Program to Implement the Vizing’s Theorem

Farhan Muhamed
Farhan Muhamed
Updated on 16-Jun-2025 371 Views

In this article, we will explain the Vizing's theorem and implement it in C++ to color a graph using the Greedy Coloring Algorithm. What is Vizing's Theorem? Vizing's theorem states that for any graph, the minimum number of colors needed to color the edges (chromatic index) is either equal to the maximum degree G of the graph or one more than maximum degree G + 1. The degree of a vertex is the number of edges connected to it. The maximum degree G refer to highest degree for any vertex in the graph. It is ...

Read More

C++ Program to Check Cycle in a Graph using Topological Sort

Farhan Muhamed
Farhan Muhamed
Updated on 16-Jun-2025 577 Views

In this problem, we are given adjacency lists of a directed graph and we need to check if there is a cycle in the graph using topological sort. If a cycle exists, it is not possible to perform a topological sort. Example: // Input Graph ( as adjacency list ) 0 -> 1 1 -> 2 1 -> 3 2 -> 0 Output: Cycle exists Explanation: The graph has a cycle (0 -> 1 -> 2 -> 0). To solve this problem, we can use Khan's Algorithm, which is a BFS based topological sorting algorithm. To ...

Read More

C++ program to Implement Threaded Binary Tree

Farhan Muhamed
Farhan Muhamed
Updated on 16-Jun-2025 5K+ Views

Threaded binary tree is a binary tree that provides the facility to traverse the tree in a particular order. In this article, we will learn all about threaded binary trees, their types, and how to implement them in C++. What is a Threaded Binary Tree? A threaded binary tree is a type of binary tree in which NULL pointers are replaced with pointers to the in-order predecessor and successor nodes. This treading will help in faster traversal of the tree without using a stack or recursion. The image below shows a threaded binary tree. There are two types ...

Read More

C++ Program to Find All Forward Edges in a Graph

Farhan Muhamed
Farhan Muhamed
Updated on 16-Jun-2025 381 Views

In this article, we will learn how to write an algorithm an C++ code to find all forward edges in a directed graph. What is a Forward Edge? A forward edge is an edge in a directed graph that points from a node to one of it's descendants in the depth-first search (DFS) tree. To understand this concept better, consider the image of a directed graph below: In the above graph, the edge from node 2 to node 5 is a forward edge because to reach node 5 in DFS traversal, we need to move through node ...

Read More

C++ Program to Check if a Given Set of Three Points Lie on a Single Line or Not

Farhan Muhamed
Farhan Muhamed
Updated on 16-Jun-2025 927 Views

In this problem, you are given three coordinates in a 2D plane, and you need to check if these three points are collinear, meaning they lie on a single straight line. There are two approaches to solve this problem. In this article, we will explain both the approaches with example code in C++. // Input: Coordinates of three points points = {{2, 3}, {4, 6}, {6, 9}}; // Output The points are collinear. Check if Three Points are Collinear If three points lie on a single line, then the points are called as collinear points. ...

Read More
Showing 361–370 of 25,433 articles
« Prev 1 35 36 37 38 39 2544 Next »
Advertisements