Found 26504 Articles for Server Side Programming

Python Indexing a sublist

Hafeezul Kareem
Updated on 07-Jul-2020 08:51:13

2K+ Views

In this tutorial, we are going to write a program that finds the index of a sublist element from the list. Let's see an example to understand it clearly.Inputnested_list = [[1, 2, 3], [4, 5], [6, 7, 8, 9]]OutputIndex of 7:- 2 Index of 5:- 1 Index of 3:- 0Let's see the simple and most common way to solve the given problem. Follow the given steps solve it.Initialize the list.Iterate over the list using the index.Iterate over the sub list and check the element that you want to find the index.If we find the element then print and break itExample Live ... Read More

Python Index specific cyclic iteration in list

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

1K+ Views

In this tutorial, we are going to write a program that cyclically iterates a list from the given Let's see the steps to solve the problemInitialize the list and index.Find the length of the list using len.Iterate over the list using the length.Find the index of the element using index % length.Print the element.Increment the index.It's a simple loop iteration. You can write it without any trouble. Let's see the code.Example Live Demo# initializing the list and index alphabets = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] start_index = 5 # finding the length length = len(alphabets) # iterating over ... Read More

Python How to sort a list of strings

Hafeezul Kareem
Updated on 07-Jul-2020 08:44:24

754 Views

In this tutorial, we are going to see how to sort a list of strings. We'll sort the given list of strings with sort method and sorted function. And then we'll see how to sort the list of strings based on different criteria like length, value, etc., Let's see how to sort a list of strings using list.sort() method. The sort method list is an insort. It'll directly sort the original list. Let's see the code.Example Live Demo# list of strings strings = ['Python', 'C', 'Java', 'Javascript', 'React', 'Django', 'Spring'] # sorting the list in ascending order strings.sort() # printing the ... Read More

Python Holidays library

Hafeezul Kareem
Updated on 07-Jul-2020 08:41:43

2K+ Views

In this tutorial, we are going to learn about the holidays library. The holidays library will help to determine whether a particular is a holiday or not in different countries. We can only see the public holidays.Let's install the module with the following command.pip install holidaysAfter successfully installing the module follow the ways to see get the holidays information. see the holidays of India in the year 2020. You have to follow the below steps to get a complete list of holidays for India in 2020.You can find the country codes for the holidays here..Import the holidays' module.Instantiate the holidays.India() ... Read More

Python Grouping similar substrings in list

Hafeezul Kareem
Updated on 07-Jul-2020 08:40:00

3K+ Views

In this tutorial, we are going to write a program that groups similar substrings from a list. Let's see an example to understand it more clearly.Inputstrings = ['tutorials-python', 'tutorials-c', 'tutorials-java', 'tutorials-javascript', 'python-1', 'python-2', 'javascript-1']Output[['tutorials-python', 'tutorials-c', 'tutorials-java', 'tutorials-javascript'], ['python-1', 'python-2'], ['javascript-1']]We are going to use the groupby method from itertools module to solve the problem. The groupby method will group all the similar string into an iter object. For the given list we have split the string with - and pass the first part of the string to the groupby method.Let's see the steps involved in solving this problem.Initialize the list ... Read More

Java Program for Iterative Merge Sort

Alshifa Hasnain
Updated on 25-Feb-2025 19:21:22

551 Views

In this article, we will learn about iterative Merge sort in Java. Unlike the traditional iterative Merge Sort, the following Java program implements a recursive merge step while dividing the array and an iterative approach for merging. What is merge sort? Merge Sort is a popular sorting algorithm that follows the Divide and Conquer rule. It recursively divides the array into two halves, sorts each half, and then merges them back in a sorted manner.The following are three main steps to perform Merge sort in Java − Divide: The array is split into two halves ... Read More

How to write text and output it as a text file using R?

Nizamuddin Siddiqui
Updated on 11-Jul-2020 12:56:06

800 Views

The easiest way to write text and obtain it as an output is done by using writeLines function and cat function, and the output of these functions are connected with the help fileConn and sink.Example> fileConn writeLines(c("TutorialsPoint", "SIMPLY EASY LEARNING"), fileConn) > close(fileConn)We can do the same and view these files in R as follows −> fileConn writeLines(c(paste("TutorialsPoint", "E-learning"), "2006", "Video Courses", "Tutorials", "Books"), fileConn) > close(fileConn) > file.show("example.txt")Using sink function> sink("example3.txt") > cat("TutorialsPoint", "E-learning") > cat("") > cat("2006") > cat("") > cat("Video Courses") > cat("") > cat("Tutorials") > cat("") > cat("Books") > sink()Using only cat function> cat("TutorialsPoint E-learning", ... Read More

Which function should be used to load a package in R, require or library?

Nizamuddin Siddiqui
Updated on 06-Jul-2020 15:02:01

531 Views

The main difference between require and library is that require was designed to use inside functions and library is used to load packages. If a package is not available then library throws an error on the other hand require gives a warning message.Using library> library(xyz) Error in library(xyz) : there is no package called ‘xyz’Using requirerequire(xyz) Loading required package: xyz Warning message: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called ‘xyz’Here we can see that the library shows an error and require gives a warning message, since warnings are mostly avoided ... Read More

How to deal with “could not find function” error in R?

Nizamuddin Siddiqui
Updated on 06-Jul-2020 15:01:06

10K+ Views

The error “could not find function” occurs due to the following reasons −Function name is incorrect. Always remember that function names are case sensitive in R.The package that contains the function was not installed. We have to install packages in R once before using any function contained by them. It can be done as install.packages("package_name")The package was not loaded before using the function. To use the function that is contained in a package we need to load the package and it can be done as library("package_name").Version of R is older where the function you are using does not exist.If you ... Read More

How to do an inner join and outer join of two data frames in R?

Nizamuddin Siddiqui
Updated on 06-Jul-2020 15:00:12

848 Views

An inner join return only the rows in which the left table have matching keys in the right table and an outer join returns all rows from both tables, join records from the left which have matching keys in the right table. This can be done by using merge function.ExampleInner Join> df1 = data.frame(CustomerId = c(1:5), Product = c(rep("Biscuit", 3), rep("Cream", 2))) > df1   CustomerId Product 1 1 Biscuit 2 2 Biscuit 3 3 Biscuit 4 4 Cream 5 5 Cream > df2 = data.frame(CustomerId = c(2, 5, 6), City = c(rep("Chicago", 2), rep("NewYorkCity", 1))) > df2 CustomerId City ... Read More

Advertisements