Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 113 of 196

Python - Ways to create triplets from given list

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 440 Views

A list is a collection which is ordered and changeable. In Python lists are written with square brackets. You access the list items by referring to the index number. Negative indexing means beginning from the end,  -1 refers to the last item. You can specify a range of indexes by specifying where to start and where to end the range. When specifying a range, the return value will be a new list with the specified items.Example# triplets from list of words. # List of word initialization list_of_words = ['I', 'am', 'Vishesh', 'and', 'I', 'like', 'Python', 'programming'] # Using list comprehension List ...

Read More

Python - Ways to find indices of value in list

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 255 Views

Usually, we require to find the index, in which the particular value is located. There are many method to achieve that, using index() etc. But sometimes require to find all the indices of a particular value in case it has multiple occurrences in list.Example# using filter() # initializing list test_list = [1, 3, 4, 3, 6, 7] # printing initial list print ("Original list : " + str(test_list)) # using filter() # to find indices for 3 res_list = list(filter(lambda x: test_list[x] == 3, range(len(test_list))))         # printing resultant list print ("New indices list : " + str(res_list)) # ...

Read More

Python - Ways to flatten a 2D list

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ Views

A list is a collection which is ordered and changeable. In Python lists are written with square brackets. You access the list items by referring to the index number. Negative indexing means beginning from the end,  -1 refers to the last item. You can specify a range of indexes by specifying where to start and where to end the range. When specifying a range, the return value will be a new list with the specified items.Example# using chain.from_iterables # import chain from itertools import chain ini_list = [[1, 2, 3],    [3, 6, 7],    [7, 5, 4]]     # ...

Read More

Python - Ways to format elements of given list

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 3K+ Views

A list is a collection which is ordered and changeable. In Python lists are written with square brackets. You access the list items by referring to the index number. Negative indexing means beginning from the end,  -1 refers to the last item. You can specify a range of indexes by specifying where to start and where to end the range. When specifying a range, the return value will be a new list with the specified items.Example# List initialization Input = [100.7689454, 17.232999, 60.98867, 300.83748789] # Using list comprehension Output = ["%.2f" % elem for elem in Input]   # Printing output ...

Read More

Python - Ways to invert mapping of dictionary

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 423 Views

Dictionary is a collection which is unordered, changeable and indexed. In Python, dictionaries are written with curly brackets, and they have keys and values. It is widely used in day to day programming, web development, and machine learning.Example# using dict comprehension # initialising dictionary ini_dict = {101: "vishesh", 201 : "laptop"} # print initial dictionary print("initial dictionary : ", str(ini_dict)) # inverse mapping using dict comprehension inv_dict = {v: k for k, v in ini_dict.items()} # print final dictionary print("inverse mapped dictionary : ", str(inv_dict)) # using zip and dict functions # initialising dictionary ini_dict = {101: "vishesh", 201 : ...

Read More

Python - Which is faster to initialize lists?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 256 Views

Python is a very flexible language where a single task can be performed in a number of ways, for example initializing lists can be performed in many ways. However, there are subtle differences in these seemingly similar methods. Python which is popular for its simplicity and readability is equally infamous for being slow compared to C++ or Java. The ‘for’ loop is especially known to be slow whereas methods like map() and filter() known to be faster because they are written in C.Example# import time module to calculate times import time # initialise lists to save the times forLoopTime = ...

Read More

How to solve the simultaneous linear equations in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 2K+ Views

The data in simultaneous equations can be read as matrix and then we can solve those matrices to find the value of the variables. For example, if we have three equations as −x + y + z = 6 3x + 2y + 4z = 9 2x + 2y – 6z = 3then we will convert these equations into matrices and solve them using solve function in R.Example1> A AOutput   [, 1] [, 2] [, 3] [1, ] 1    1    2 [2, ] 3    2    4 [3, ] 2    3    -6> b bOutput[, 1] ...

Read More

How to remove a character in an R data frame column?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 51K+ Views

To remove a character in an R data frame column, we can use gsub() function which will replace the character with blank. For example, if we have a data frame called df that contains a character column say x which has a character ID in each value then it can be removed by using the command gsub("ID", "", as.character(df$x)).Example1Consider the below data frame −> x1 x2 df1 df1Output        x1  x2 1    Male1  8 2  Female1  4 3    Male1  9 4    Male1  2 5    Male1  7 6  Female1  5 7    Male1  3 8 ...

Read More

How to convert more than one column in R data frame to from integer to numeric in a single line code?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 49K+ Views

To convert columns of an R data frame from integer to numeric we can use lapply() function. For example, if we have a data frame df that contains all integer columns then we can use the code lapply(df,as.numeric) to convert all of the columns data type into numeric data type.Example1Consider the below data frame −set.seed(871) x1

Read More

How to find the R version you are using?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 47K+ Views

Most of the times, we need to use packages in R and some packages are restricted to different versions in R, generally to newer versions. Therefore, we might need to find which version of R we are using. To find the R version, we can directly use the command R.Version().ExampleR.version.stringOutput[1] "R version 4.0.2 (2020−06−22)"

Read More
Showing 1121–1130 of 1,958 articles
« Prev 1 111 112 113 114 115 196 Next »
Advertisements