Found 26504 Articles for Server Side Programming

Find the second most repeated word in a sequence in Java

AmitDiwan
Updated on 08-Jul-2020 10:20:18

677 Views

To find the second most repeated word in a sequence in Java, the code is as follows −Example Live Demoimport java.util.*; public class Demo{    static String second_repeated(Vector my_seq){       HashMap my_map = new HashMap(my_seq.size()){          @Override          public Integer get(Object key){             return containsKey(key) ? super.get(key) : 0;          }       };       for (int i = 0; i < my_seq.size(); i++)       my_map.put(my_seq.get(i), my_map.get(my_seq.get(i))+1);       int first_val = Integer.MIN_VALUE;       int sec_val ... Read More

Find the first repeated word in a string in Java

AmitDiwan
Updated on 08-Jul-2020 10:17:39

950 Views

To find the first repeated word in a string in Java, the code is as follows −Example Live Demoimport java.util.*; public class Demo{    static char repeat_first(char my_str[]){       HashSet my_hash = new HashSet();       for (int i=0; i

Find the uncommon values concatenated from both the strings in Java

AmitDiwan
Updated on 08-Jul-2020 10:16:20

272 Views

To find the uncommon values concatenated from both the strings in Java, the code is as follows −Example Live Demoimport java.util.*; import java.lang.*; import java.io.*; public class Demo{    public static String concat_str(String str_1, String str_2){       String result = "";       int i;       HashMap my_map = new HashMap();       for (i = 0; i < str_2.length(); i++)       my_map.put(str_2.charAt(i), 1);       for (i = 0; i < str_1.length(); i++)       if (!my_map.containsKey(str_1.charAt(i)))       result += str_1.charAt(i);       else       ... Read More

Java program to display Hostname and IP address

AmitDiwan
Updated on 28-Aug-2024 21:18:08

4K+ Views

In this article, we will learn to display the Hostname and IP address using Java. To display the Hostname and IP address we will be using the InetAddress class from the java.net package. We’ll write a simple program to fetch and print this information, and perform the exception handling to catch the exception if the data isn't found. Problem Statement Write a program in Java to display the Hostname and IP address. Below is a demonstration of the same − Output  The IP address is : 127.0.0.1The host name is : jdoodle Steps to display Hostname and IP address Following are ... Read More

Python Grouped Flattening of list

Hafeezul Kareem
Updated on 07-Jul-2020 09:04:25

180 Views

In this tutorial, we are going to write a program that flattens a list that contains sub-lists. Given number flatten the sublists until the given number index as parts. Let's see an example to understand it clearly.Inputlists = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]] number = 2Output[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10]]Let's see the steps to solve the problem.Initialize the list and number.Initialize an empty list.Iterate over the list with range(0, len(lists), number.Get the sublists using slicing lists[i:number].Iterate over the sublists and append the resultant list to the result list.Print the result.Example# ... Read More

Python Group by matching second tuple value in list of tuples

Hafeezul Kareem
Updated on 07-Jul-2020 09:03:26

482 Views

In this tutorial, we are going to write a program that groups all the tuples from a list that have same element as a second element. Let's see an example to understand it clearly.Input[('Python', 'tutorialspoints'), ('Management', 'other'), ('Django', 'tutorialspoints'), ('React', 'tutorialspoints'), ('Social', 'other'), ('Business', 'other')]Output{'tutorialspoint': [('Python', 'tutorialspoints'), ('Django', 'tutorialspoints'), ('React', 'tutorialspoints')], 'other’: [('Management', 'other'), ('Social', 'other'), ('Business', 'other')]}We have to group the tuples from the list. Let's see the steps to solve the problem.Initiate a list with required tuples.Create an empty dictionary.Iterate through the list of tuples.Check if the second element of the tuple is already present in the dictionary ... Read More

Python Grayscaling of Images using OpenCV

SaiKrishna Tavva
Updated on 13-Nov-2024 14:29:19

4K+ Views

Grayscaling an image includes converting a color image into a grayscale image. By using OpenCV library in various methods we can convert the color image with (multiple color channels) into a grayscale image (with a single channel). Some of the common methods for greyscaling an image using OpenCV are as follows. cv2.cvtColor(): This function is used to convert an image from one space color to another. Pixel ... Read More

Python Getting started with psycopg2-PostgreSQL

Hafeezul Kareem
Updated on 07-Jul-2020 08:57:48

926 Views

In this tutorial, we are going to learn how to use PostgreSQL with Python. You have to install certain thing before going into the tutorial. Let's install them.Install the PostgreSQL with the guide..Install the Python module psycopg2 for PostgreSQL connection and working. Run the command to install it.pip install psycopg2Now, open the pgAdmin. And create a sample database. Next, follow the below steps to get started with database operations.Import the psycopg2 module.Store the database name, username, and password in separate variables.Make a connection to the database using psycopg2.connect(database=name, user=name, password=password) method.Instantiate a cursor object to execute SQL commands.Create queries and ... Read More

Python How to copy a nested list

Hafeezul Kareem
Updated on 07-Jul-2020 08:53:49

483 Views

In this tutorial, we are going to see different ways to copy a nested list in Python. Let's see one by one.First, we will copy the nested list using loops. And it's the most common way.Example Live Demo# initializing a list nested_list = [[1, 2], [3, 4], [5, 6, 7]] # empty list copy = [] for sub_list in nested_list:    # temporary list    temp = []    # iterating over the sub_list    for element in sub_list:       # appending the element to temp list       temp.append(element)    # appending the temp list to copy ... Read More

Python Indices of numbers greater than K

Hafeezul Kareem
Updated on 07-Jul-2020 08:52:46

564 Views

In this tutorial, we are going to find the indices of the numbers that are greater than the given number K. Let's see the different ways to find them.A most common way to solve the problem is using the loops. Let's see the steps to solve the problem.Initialize the list and K.Iterate over the list using its length.If you find any number greater than K, then print the current index.Example Live Demo# initializing the list and K numbers = [3, 4, 5, 23, 12, 10, 16] K = 10 # iterating over thAe list for i in range(len(numbers)):    # checking ... Read More

Advertisements