We may have a need to associate a given value with each and every element of a list. For example − there are the name of the days and we want to attach the word day as a suffix in them. Such scenarios can be handled in the following ways.With itertools.repeatWe can use the repeat method from itertools module so that the same value is used again and again when paired with the values from the given list using the zip function.Example Live Demofrom itertools import repeat listA = ['Sun', 'Mon', 'Tues'] val = 'day' print ("The Given list : ... Read More
There are different scoping rules for lambda expression in Java. In lambda expressions, this and super keywords are lexically scoped means that this keyword refers to the object of the enclosing type and the super keyword refers to the enclosing superclass. In the case of an anonymous class, they are relative to the anonymous class itself. Similarly, local variables declared in lambda expression conflicts with variables declared in the enclosing class. In the case of an anonymous class, they are allowed to shadow variables in the enclosing class.Example@FunctionalInterface interface TestInterface { int calculate(int x, int y); } class Test { public ... Read More
The lambda expressions are easy and contain three parts like parameters (method arguments), arrow operator (->) and expressions (method body). The lambda expressions can be categorized into three types: no parameter lambda expressions, single parameter lambda expressions and multiple parameters lambda expressions.Lambda Expression with no parameterWe need to create no parameter lambda expression then start the expression with empty parenthesis.Syntax() -> { //Body of no parameter lambda }Example(no parameter Lambda)import java.util.function.*; import java.util.Random; public class LambdaExpression1 { public static void main(String args[]) { NumberUtil num = new NumberUtil(); int randVal = num.getRandomValue( ... Read More
A lambda block states that lambda expression with multiple statements. It expands the type of operations to perform with a lambda expression. The multiple statements containing bodies are called expression bodies. A lambda expression with expression bodies is called expression lambdas. Whenever we are using expression lambdas, explicitly use a return statement to return a value.Exampleinterface NumberFinder { int finder(int number1, int number2); } public class LambdaNumberFinder { public static void main(String args[]) { NumberFinder numberFinder = (number1, number2) -> { int temp = 0; if(number1 > number2) ... Read More
The lambda expressions are anonymous functions and don't have any return type, access modifier and not belonging to any class. It can be used to simplify the implementation of the abstract method in a functional interface. Whenever there is a functional interface, we can use lambda expressions instead of anonymous inner classes.Syntax([comma seperated argument-list]) -> {body}Example@FunctionalInterface interface BonusCalculator { public double calcBonus(int amount); } class EmpDetails { public void getBonus(BonusCalculator calculator, int amount) { double bonus = calculator.calcBonus(amount); System.out.println("Bonus: " + bonus); } } public class LambdaExpressionTest { public static void main(String[] ... Read More
In this tutorial, we will be discussing a program to implement Run Length Encoding using Linked Lists.For this we will be given with a linked list. OUr task is too encode the elements of the Linked List using Run Length Encoding.For example, if the elements of the linked list are “a->a->a->a->a” then in run length encoding they will be replaced by “a → 5”.Example#include using namespace std; //structuring linked list node struct Node { char data; struct Node* next; }; //creating a new node Node* newNode(char data){ Node* temp = new Node; temp->data = data; ... Read More
The Object.GetTypeCode() method in C# is used to get the Type of the current instance.SyntaxThe syntax is as follows −public Type GetType ();Example Live Demousing System; public class Demo { public static void Main() { Object ob = new Object(); String str = "Jim"; Type type1 = ob.GetType(); Type type2 = str.GetType(); Console.WriteLine("Type = "+type1); Console.WriteLine("Type = "+type2); Console.WriteLine("Hash Code = "+type1.GetHashCode()); Console.WriteLine("Hash Code = "+type2.GetHashCode()); } }OutputType = System.Object Type = System.String Hash Code = 30015890 Hash Code = 21083178Example Live Demousing System; ... Read More
Every programming language has a error handling mechanism in which some errors are already coded into the compiler. In Python we have love which are associated with some standard pre-determined error codes. In this article we will see how to to get the error numbers as well as error codes which are inbuilt. And then take an example of how error code can be used.Error codesIn this program just list out the inbuilt error numbers and error codes. Memorial we use the error no module along with the OS module.Example Live Demoimport errno import os for i in sorted(errno.errorcode): print(i, ... Read More
In this article we will see how we can generate secure Random numbers which can be effectively used as passwords. Along with the Random numbers we can also add letters and other characters to make it better.with secretsThe secrets module has a function called choice which can be used to generate the password of required length using a for loop and range function.Example Live Demoimport secrets import string allowed_chars = string.ascii_letters + string.digits + string.printable pswd = ''.join(secrets.choice(allowed_chars) for i in range(8)) print("The generated password is: ", pswd)OutputRunning the above code gives us the following result −The generated password is: $pB7WYwith ... Read More
Suppose we have a string which contains numbers are the beginning. In this article we will see how to get only the numeric part of the string which is fixed at the beginning.With isdigitThe is digit function decides if the part of the string is it digit or not. So we will use takewhile function from itertools to join each part of the string which is a digit.Example Live Demofrom itertools import takewhile # Given string stringA = "347Hello" print("Given string : ", stringA) # Using takewhile res = ''.join(takewhile(str.isdigit, stringA)) # printing resultant string print("Numeric Pefix from the string: ", ... Read More
 
 Data Structure
 Data Structure Networking
 Networking RDBMS
 RDBMS Operating System
 Operating System Java
 Java MS Excel
 MS Excel iOS
 iOS HTML
 HTML CSS
 CSS Android
 Android Python
 Python C Programming
 C Programming C++
 C++ C#
 C# MongoDB
 MongoDB MySQL
 MySQL Javascript
 Javascript PHP
 PHP 
		 
		 
		