Use Named Groups in Python Regular Expressions

SaiKrishna Tavva
Updated on 15-Apr-2025 12:25:01

1K+ Views

Usually, if we need to find a particular word such as, "data" in a text or a string we will directly search for it. We can also use a sequence of characters which forms a pattern to search for words in a string. For example the characters "[0-9]" matches a single digit number and "[0-9]+" matches any string containing one or more digits. These sequence of characters are known as regular expressions. Groups in Python Regular Expressions Like any other programming Python provides a module named re to handle regular expressions. The methods re.match() and re.search() of this module are ... Read More

Why Python Returns Tuple in List Instead of List in List

SaiKrishna Tavva
Updated on 15-Apr-2025 12:23:49

506 Views

In Python, especially in situations like iterating through data structures, working with built-in functions, or fetching records from a database, lists of tuples are returned by the pre-defined functions instead of a list of lists. This is because tuples are immutable i.e., we cannot modify them after creation, whereas lists are mutable; once obtained, we can change their contents. This makes tuples ideal for storing fixed data like database records or function results, ensuring data integrity. Let us see methods/functions in Python that return a list of tuples - The enumerate() Function The enumerate() function is used to add a counter to ... Read More

Install Python Modules on a Mac

Sumana Challa
Updated on 15-Apr-2025 10:38:14

365 Views

Installing Python Modules on Mac Managing Python packages efficiently is important for developers; this can be challenging, especially while working on macOS. In this article, there will be a list of different options to install Python modules on a Mac from which you could choose one that is reliable and easy to use. Some common ways to install Python modules in macOS are listed below - Using EasyInstall Using Pip Using Homebrew Using Virtual Environment Using EasyInstall The most popular way to ... Read More

Importance of Cursor Class in Java

Alshifa Hasnain
Updated on 14-Apr-2025 19:25:36

2K+ Views

In this article, we will learn about the importance of the Cursor class in Java. Under the Swing toolkit, the Cursor class provides an improved user experience by providing graphical(visual) feedback. What is a Cursor class? A Cursor is a subclass of the Object class, and it can be defined as point or indicator on the screen. A Cursor is used to select the input from the system that the user operates with the mouse. The important methods of Cursor class are getDefaultCursor(), getName(), getPredefinedCursor(), getSystemCustomCursor(), and getType(). Syntax The following is the syntax: Cursor cursor = new Cursor(Type_of_Cursor); Different ... Read More

Sort JTable on a Particular Column in Java

raja
Updated on 14-Apr-2025 19:20:26

4K+ Views

In this article, we will learn to sort a JTable on a particular column in Java. Data sorting in a JTable is something that most Java Swing applications require. If the users can sort table data by clicking on column headers, it improves the experience greatly. What is a JTable? A JTable is a subclass of JComponent class for displaying complex data structures. A JTable component can follow the Model View Controller (MVC) design pattern for displaying the data in rows and columns. Syntax The following is the syntax: JTable table = new JTable(data, columnNames); A JTable can generate different ... Read More

Difference Between strncmp and strcmp in C/C++

George John
Updated on 14-Apr-2025 19:16:27

2K+ Views

Both strncmp() and strcmp() are used in C/C++ programs for lexicographical string comparison. The strcmp() compares two strings till the null character is found, whereas strncmp() only compares a specified number of characters. What is strncmp() ? The function strncmp() is used to compare left string to right string up to a number. It works same as strcmp(). It returns a value greater than zero when the matching character of left string has greater ASCII value than the character of the right string. Returns a value less than zero when the matching character of left string has lesser ASCII value ... Read More

Clear Console in C

Samual Sam
Updated on 14-Apr-2025 19:13:13

22K+ Views

In C, we have various methods to clear the console or output screen and one of them is clrscr() function. It clears the screen as function invokes. It is declared in "conio.h" header file. There are some other methods too like system (cls) and system ("clear") and these are declared in "stdlib.h" header file. Syntax Following are the list of syntaxes to clear the console in C programming language as follows: clrscr(); Or, system("cls"); Or, system("clear"); Let’s say we have "new.txt" file with the following content: 0, hell!o 1, hello! 2, gfdtrhtrhrt 3, ... Read More

Swap Two Variables in One Line in C/C++

Tapas Kumar Ghosh
Updated on 14-Apr-2025 18:23:50

2K+ Views

In C++, swapping two variables means exchanging the values stored in them. There can be multiple ways to implement the swapping using single line statement. In this article, we are going to learn some of the approaches to swap the values. Example Let's consider the following example with input and output scenario: Input: int a = 5; int b = 6; Output: a = 6 b = 5 You can implement swapping of two variable by using the following different ways: Using Arithmetic Operator Using Tuple Using XOR Swap Two Variables Using Arithmetic Operator In ... Read More

What Should main() Return in C and C++

Tapas Kumar Ghosh
Updated on 14-Apr-2025 18:00:03

3K+ Views

In C/C++, the main() function is used in the beginning of every program. This returns the program execution status in the operating system. Syntax Following is the syntax of the main() function using C/C++: int main(void); int main(int argc, char *argv[]); Example Below, the C/C++ example shows the usage of the main() return value. C C++ #include int main() { printf("Hello, C World!"); return 0; } Key Points of C Return 0: This is standard for successful execution Non-zero: It indicates error Implicit return: C99 allows omitting return #include int main() { std::cout

Install Unidecode Python Module on Linux

Sumana Challa
Updated on 14-Apr-2025 17:31:41

2K+ Views

What is Unidecode? Unidecode is a Python module that helps convert unidecode text into plain ASCII characters. This is mostly used when the text contains special characters or non-English characters, and you need to simplify it. For example, it converts "kožušček" to "kozuscek", "北京" to "Bei Jing", and "naïve" to "naive". This module is popularly used to simplify for processing or display of user-generated content and international data [multi-lingual]. Installing Python Unidecode Module To install unidecode or any other Python module, you need pip installed(Python package manager). If you have Python 2 >=2.7.9 or Python 3 ... Read More

Advertisements