Found 34469 Articles for Programming

Filter Range Length Tuples in Python

Tapas Kumar Ghosh
Updated on 17-Jul-2023 17:59:50

336 Views

A range length is defined by representing range of values that follow the start and end point along with the length. In Python, there are some built-in functions like list(), append(), filter(), and, lambda which can be used to solve the problem based on Filter Range Length Tuples. This type of problem statement normally helps to build the logic of filtering tool. Syntax The following syntax is used in the examples − len() The len() is the built-in method in Python that returns the length of the object. append() The append method in Python is used to add ... Read More

How to Convert a Matrix to a Dictionary in Python

Tapas Kumar Ghosh
Updated on 17-Jul-2023 17:47:51

332 Views

The matrix is defined by arranging rows and columns to form an array. The values of a matrix in rows and columns either be characters or integers. There are various method names- dictionary comprehension, for loop, enumerate, and, zip() that will be used to Convert a Matrix to a Dictionary in Python. Using a for Loop and Dictionary Comprehension The program uses the for loop that will iterate the length of the matrix by applying dictionary comprehension. This helps the conversion of the matrix into a dictionary. Example In the following example, we will show the name values of matrix ... Read More

Convert Snake Case String to Camel Case using Python

Tapas Kumar Ghosh
Updated on 17-Jul-2023 17:43:29

1K+ Views

The snake case string is the naming convention where words are instead separated by an underscore(‘-’). The Camel case is defined by two or more words connected together without spaces and the first letter of each word being capitalized. There are various built-in methods in Python such as split(), join(), and, re.sub() that can be used to convert Snake Case String to Camel Case using Python. Let’s take an example of this − Snake Case String − hello_world(having separator i.e. underscore ‘_’) Camel Case String − helloWorld(when we convert the Snake case into Camel case it allows the second ... Read More

Convert Lists to Nested Dictionary in Python

Tapas Kumar Ghosh
Updated on 17-Jul-2023 17:42:11

471 Views

The list is defined by an ordered sequence of elements whereas the nested dictionary defines the dictionary include another dictionary. The nested dictionary is required when we want to store large data in a big dictionary. In Python, we have some built-in functions like reduce() and zip() that Convert Lists into Nested Dictionary. For example- Dictionary data communicate the structural content of data which is easier to understand. Syntax The following syntax is used in the examples − reduce() This built-in function in Python follows the functools module to perform a specific operation on lists. zip() The zip() ... Read More

How to select a range of rows from a dataframe in PySpark?

Tapas Kumar Ghosh
Updated on 17-Jul-2023 17:19:48

786 Views

The dataframe in PySpark is defined by a shared collection of data that can be used to run in computer machines and structurize the data into rows and columns format. The range of rows defines a horizontal line(set of multiple values according to condition) in the dataset. In general, the range sets the lowest and highest values. In Python, we have some built-in functions like filter(), where(), and, collect() to select a range of rows from a dataframe in PySpark. Syntax The following syntax is used in the examples − createDataFrame() This is a built-in method in Python ... Read More

Sort an Array of Strings in Lexicographical Order

Shubham Vora
Updated on 17-Jul-2023 16:36:54

637 Views

In this problem, we will sort the array of strings in the lexicographical order. There are various sorting algorithms to sort the array of strings. In this tutorial, we will use the built−in sort() method to sort the strings. Also, we will use the merge sort algorithm, one of the efficient approaches to sort the array of strings. Problem statement − We have given an str[] array containing N strings. We need to sort all strings in the lexicographical order. Sample examples Input str[] = {"tutorials", "point", "save", "java", "c++"} Output c++, java, point, save, tutorials ... Read More

How to slice a PySpark dataframe in two row-wise dataframe?

Tapas Kumar Ghosh
Updated on 17-Jul-2023 16:52:47

589 Views

PySpark dataframe is defined as a collection of distributed data that can be used in different machines and generate the structure data into a named column. The term slice is normally used to represent the partitioning of data. In Python, we have some built-in functions like limit(), collect(), exceptAll(), etc that can be used to slice a PySpark dataframe in two row-wise dataframe. Syntax The following syntax is used in the examples − limit() This is a built-in method in Python that can be used to set the range of rows by specifying the integer value. subtract() The ... Read More

Reverse given Range of String for M queries

Shubham Vora
Updated on 17-Jul-2023 16:34:47

203 Views

In this problem, we will perform M reverse queries on the given string according to the array values. The naïve approach to solving the problem is to reverse each string segment according to the given array value. The optimized approach uses the logic that when we reverse the same substring two times, we get the original string. Problem statement − We have given an alpha string containing the alphabetical characters. Also, we have given an arr[] array of size M containing the positive integers. We need to perform the M operations on the given string and return the final ... Read More

How to Set Axis Limits bokeh?

Tapas Kumar Ghosh
Updated on 17-Jul-2023 16:49:05

210 Views

Bokeh is a built-in Python library that makes a highly interactive graph for data visualization. Generally, web developers use this library to build powerful dashboards, live app applications, and, simple charts on the web. In Python, we have some bokeh built-in functions like figure(), vbar(), y_range(), etc. to Set Axis Limits bokeh. The various field used this library such as Data Scientists, Data Engineers, and, Web Developers. Syntax The following syntax is used in the examples − figure() The figure is a built-in method of bokeh library and it is known for a subclass of plot that simply create ... Read More

Parity of Count of Letters whose Position and Frequency have Same Parity

Shubham Vora
Updated on 17-Jul-2023 16:32:47

91 Views

In this problem, we will count the number of characters whose frequency and position have the same parity and print the count of the number as odd or even. To solve the problem, we can find the frequency of each character in the string, and count total characters whose freqeuncy and position have the same parity. After that, we can print the odd or even answer based on the counts. Problem statement − We have given a string alpha containing only lowercase english alphabetical characters. We need to check whether the number of characters having equal parity of their alphabetical ... Read More

Advertisements