A Python list is a built-in, mutable datatype that stores multiple items or elements, separated by commas, within square brackets [ ]. The index of a list in Python starts from 0 up to length-1. We can retrieve/access elements at a particular index as follows - list_name[index] The given task is to write a Python program that prints the first character of each element in a list. But, before that, let's see some example scenarios: Scenario 1 For example, if our list contains string values, the output should be the first character of each string. Input: list = ... Read More
With the increase in popularity of the Python programming language, more and more features are becoming available for Python developers. Usage of these features helps us to write efficient code. In this article, we will see 10 Python tricks that are very frequently used. Reversing a List We can reverse a given list by using the reverse() function. It returns the elements of the current list in reverse order. It works with both numeric and string datatypes. Example Let's see how to use the reverse() function in your Python program to reverse a list of strings: List = ["Shriya", "Lavina", "Sampreeti" ... Read More
Tokenization is the process of splitting a string into smaller pieces (tokens). In the context of natural language processing (NLP), tokens are words, punctuation marks, and numbers. Tokenization is a preprocessing step for many NLP tasks, as it allows you to work with individual words and symbols rather than raw text. In this article, we will look at five ways to perform tokenization in Python: Using the split() Method Using the NLTK Library Using Regular Expressions Using the shlex Module Using the ... Read More
In C, the "#" and "##" are the pre-processor operators that are used to convert a macro parameter to a String Literal. The macro parameters are the parameters of the macro definition, which are declared using the #define directive. The "#" operator is known as the Stringize operator, whereas the "##" operator is known as the Token Pasting operator. The #define Directive in C The #define directive is a preprocessor command that is used to create macros in the C programming language. Here is a syntax to create macros: #define MACRO_NAME replacement_text Or #define MACRO_NAME(param1, param2, …paramN) replacement_text ... Read More
Additive Secret Sharing and Share Proactivization are cryptographic techniques to share a password or other confidential data among a group of people. In this article, we will explain these techniques and implement Python code to demonstrate them. Additive Secret Sharing Additive secret sharing is a technique used in cryptography to share a secret string or a password among multiple parties, such that all of the parties must collaborate to reconstruct the secret. For example: Original Secret Key: 1234 Generated five Shares: [-488, -55, -417, -720, 2914] Reconstructed Secret: 1234 Explanation: The original secret password is split into 5 ... Read More
Python dictionaries are built-in data structures used to store data in key-value pairs. A dictionary of lists refers to a dictionary that contains one or more lists as values for any keys. For example, # Dictionary of Lists in Python: dict = { "list1" : [1, 2, 3], "list2" : [4, 5, 6] } You are given a Python dictionary that contains empty lists, your task is to add values to the lists of dictionaries. Consider the following input output scenario: Input: { 'List1': [], 'List2': [] } Output: { 'List1': [1, 2, 3], 'List2': [4, 5, ... Read More
The _Noreturn function specifier in C indicates to the compiler that the function will either exit or run in an infinite loop. This function never returns the control to the main function or wherever it was called in the program. If the _Noreturn function uses the return statement, the compiler will generate a warning or show an undefined behavior. Syntax of _Noreturn Function Specifier The syntax of _Noreturn function specifier is given below: _Noreturn data_type function_name() { --- code lines --- } _Noreturn with exit() Function in ... Read More
The Adam number is a number such that the square of the given number 'n' is the reverse of the square of the reverse of that number 'n'. In this article, our task is to write a program that can check whether the given number is an Adam number or not. Here is an example to check whether 12 is an Adam number or not: Input: num = 12 Output: 12 is an Adam number Explanation: num = 12 , square of num = ... Read More
In C/C++, an inline function is a function where the compiler replaces the function call with the actual code of the function during compilation. So, this makes the program run faster than a normal function call. Why to Use Inline Function in C/C++? We should use an inline function in C/C++ when the function is very simple and small size. Also, avoid the regular function call and replace macros with type safety. Let us understand how an inline function is used for small functions. Suppose we write square(5), the compiler converts it directly to 5*5. This makes the program run ... Read More
Python tuples are immutable sequences that used to store collections of items. When working with two tuples, you may sometimes need to generate all possible pairs, where each pair contains one element from the first tuple and one from the second. In this article, we will learn different ways to generate all pair combinations from two tuples Following are input-output scenarios for pairing combinations of two tuples: Input: first_tuple = (1, 3) second_tuple = (7, 9) Output: [(1, 7), (1, 9), (3, 7), (3, 9), (7, 1), (7, 3), (9, 1), (9, 3)] Explanation: At index 0 of first_tuple pairs ... Read More