Word Abbreviation in C++

Arnab Chakraborty
Updated on 11-Jul-2020 11:28:19

1K+ Views

Suppose we have an array of n unique strings, We have to generate minimal possible abbreviations for every word following rules below.Starting with the first character and then the number of characters abbreviated, which followed by the last character.If we find any conflict and that is more than one words share the same abbreviation, a longer prefix can be used instead of only the first character until making the map from word to abbreviation become unique.When the abbreviation doesn't make the word shorter, then keep it as original.So, if the input is like ["like", "god", "internal", "me", "internet", "interval", "intension", ... Read More

Count Even and Odd Numbers in a List using Python

Pavitra
Updated on 11-Jul-2020 11:25:39

6K+ Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given a list, we need to count even and odd numbers in a list.There are three methods as discussed below−Approach 1 − Using brute-force approachExample Live Demolist1 = [21, 3, 4, 6, 33, 2, 3, 1, 3, 76] even_count, odd_count = 0, 0 # enhanced for loop for num in list1:    #even numbers    if num % 2 == 0:       even_count += 1    #odd numbers    else:       odd_count += 1 print("Even numbers available in the ... Read More

Count Positive and Negative Numbers in a List in Python

Pavitra
Updated on 11-Jul-2020 11:24:45

4K+ Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given a list iterable, we need to count positive and negative numbers in it and display them.Approach 1 − Brute-force approach using iteration construct(for)Here we need to iterate each element in the list using a for loop and check whether num>=0, to filter the positive numbers. If the condition evaluates to be true, then increase pos_count otherwise, increase neg_count.Example Live Demolist1 = [1, -2, -4, 6, 7, -23, 45, -0] pos_count, neg_count = 0, 0 # enhanced for loop   for num in ... Read More

Use this and super Keywords in Method Reference in Java

raja
Updated on 11-Jul-2020 08:55:49

1K+ Views

The method reference is similar to a lambda expression that refers to a method without executing it and "::" operator can be used to separate a method name from the name of an object or class in a method reference.The methods can be referenced with the help of this and super keywords in Java. The super keyword can be used as a qualifier to invoke the overridden method in a class or an interface.syntaxthis::instanceMethod TypeName.super::instanceMethodExampleimport java.util.function.Function; interface Defaults {    default int doMath(int a) {       return 2 * a;    } } public class Calculator implements Defaults { ... Read More

Target Type of Lambda Expression in Java

raja
Updated on 11-Jul-2020 08:30:22

3K+ Views

A functional Interface for which a lambda expression has invoked is called target type of lambda expression. It means that if a lambda expression has invoked for some "X" interface then "X" is the target type of that lambda expression. Hence, we conclude that lambda expressions can be used only in those situations where java compiler can determine the Target Type.In the below example, the target type of lambda expression is BiFunction. An instance of a class is automatically created that implements the functional interface and lambda expression provides an implementation of the abstract method declared by the functional interface.Exampleinterface BiFunction { ... Read More

Truncate Numbers in Python

Hafeezul Kareem
Updated on 11-Jul-2020 08:22:56

304 Views

In this tutorial, we are going to learn about the math.trunc() method.The method math.trunc() is used to truncate the float values. It will act as math.floor() method for positive values and math.ceil() method for negative values.Example Live Demo# importing math module import math # floor value print(math.floor(3.5)) # trunc for positive number print(math.trunc(3.5))OutputIf you run the above code, then you will get the similar result as follows.3 3Example Live Demo# importing math module import math # ceil value print(math.ceil(-3.5)) # trunc for negative number print(math.trunc(-3.5))OutputIf you run the above code, then you will get the similar result as follows.-3 -3ConclusionIf you have ... Read More

Time Process Time Function in Python

Hafeezul Kareem
Updated on 11-Jul-2020 08:21:15

2K+ Views

In this tutorial, we are going to learn about the time.process_time() method.The method time.process_time() will return a float value of time in seconds of a system and user CPU time of the current process.Example Live Demo# importing the time module import time # printing the current process time print(time.process_time()) 1.171875OutputIf you run the above code, then you will get the similar result as follows.1.171875Let's say we have a process that prints from in the given range. Let's find the time for that process. Understand the following code and run it.Example Live Demo# importing the time module import time # program to find ... Read More

Time Perf Counter Function in Python

Hafeezul Kareem
Updated on 11-Jul-2020 08:19:13

4K+ Views

In this tutorial, we are going to learn about the time.perf_counter() method.The method time.perf_counter() returns a float value of time in seconds. Let's see anExample Live Demo# importing the time module import time # printing the time print(time.perf_counter())OutputIf you run the above code, then you will get the following result.263.3530349We can use the time.perf_counter() method to find the execution time of a program. Let's see an example.Example Live Demo# importing the time module import time # program to find the prime number def is_prime(number):    for i in range(2, number):       if number % i == 0:       ... Read More

Most Occurring Number in a String Using Regex in Python

Hafeezul Kareem
Updated on 11-Jul-2020 08:18:27

241 Views

In this tutorial, we are going to write a regex that finds the most occurring number in the string. We will check the regex in Python.Follow the below steps to write the program.Import the re and collections modules.Initialize the string with numbers.4Find all the numbers using regex and store them in the array.Find the most occurring number using Counter from collections module.Example Live Demo# importing the modules import re import collections # initializing the string string = '1222tutorials321232point3442' # regex to find all the numbers regex = r'[0-9]' # getting all the numbers from the string numbers = re.findall(regex, string) # ... Read More

Taking Multiple Inputs from User in Python

Hafeezul Kareem
Updated on 11-Jul-2020 08:16:43

1K+ Views

In this tutorial, we are going to learn how to take multiple inputs from the user in Python.The data entered by the user will be in the string format. So, we can use the split() method to divide the user entered data.Let's take the multiple strings from the user.Example# taking the input from the user strings = input("Enter multiple names space-separated:- ") # spliting the data strings = strings.split() # printing the data print(strings)OutputIf you run the above code, then you will get the following result.Enter multiple names space-separated:- Python JavaScript Django React ['Python', 'JavaScript', 'Django', 'React']What if we want ... Read More

Advertisements