Found 10784 Articles for Python

Get the indices of Uppercase Characters in a given String using Python

Rohan Singh
Updated on 17-Jul-2023 18:24:23

1K+ Views

In Python, we can get the indices of uppercase characters in a given string using methods like using List Comprehension, using a For Loop, using Regular Expressions etc. Finding the indices of Uppercase characters can be useful in text analysis and manipulation. In this article, we will explore different methods to obtain the indices of uppercase characters in a given string. Method 1:Using List Comprehension Using list comprehension we can iterate through the characters of a string, check if they are uppercase using the isupper() method, and stores their indices in a list. It provides a concise and ... Read More

Filter Non-None dictionary keys in Python

Tapas Kumar Ghosh
Updated on 17-Jul-2023 18:26:27

277 Views

Python dictionary is one of the most popular data types among the following 4 datatypes. The dictionary defines the key with value pair and doesn’t allow the duplicate. The values are either strings or integers. Sometimes, while working on the dictionary it has some empty values that the None value can fill. For example- when we are working on a machine learning dataset it has found that some of the rows are empty and can be filled by the value None when performing the particular task. In Python, we have some built-in functions like items() and lambda that can be ... Read More

How to Filter list elements starting with a given Prefix using Python?

Tapas Kumar Ghosh
Updated on 17-Jul-2023 18:24:59

541 Views

The term prefix is defined by the beginning of the word or letter. In this article, we will learn how to use Python built-in functions like startswith(), filter(), lambda, and len() to Filter list elements starting with a given Prefix using Python. Let’s take an example to understand this − Let’s take an example to understand this: Given element list, My_list = [“Amelia”, “Kinshuk”, “Rosy”, “Aman”] Keyword to be searched, Prefix = “Am” Final result = [“Amelia”, “Aman”] Syntax The following syntax is used in all the examples − startswith() The is a built-in ... Read More

Python - Filter odd elements from value lists in dictionary

Tapas Kumar Ghosh
Updated on 17-Jul-2023 18:08:28

527 Views

The dictionary is a popular data type in Python that has a key with value pair and doesn’t allow duplicates. To filter the odd elements it has some built-in functions like items(), filter(), lambda, and, the list() will be used to Filter odd elements from value lists in the dictionary. The odd elements of the list are those elements that are not divisible by 2. For example − The given list, [10, 22, 21, 19, 2, 5] After filtering the odd elements from the list: The final result becomes [10, 22, 2] (These are the elements that are divisible by ... Read More

Filter Range Length Tuples in Python

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

332 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

321 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

457 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

775 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

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

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

587 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

Advertisements