SaiKrishna Tavva

SaiKrishna Tavva

80 Articles Published

Articles by SaiKrishna Tavva

Page 7 of 8

Word Search in Python

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 14-Oct-2024 7K+ Views

In Python word search refers to determining if a given word exists in the grid, this can be done using various approaches like DFS method and backtracking algorithm, etc, and the given word can be formed by sequentially connecting adjacent cells both horizontally or vertically. Step Involved The steps involved in performing word search in Python are as follows. Consider the input board(2D grid) Define the class ...

Read More

How to convert JSON data into a Python tuple?

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 14-Oct-2024 6K+ Views

One of the common approach to convert JSON data into a python tuple is converting the json data to a dict using json.loads() and then conveting it to a python tuple using dict.items(). There are several other ways or methods to convert JSON data into tuple, depending on our needs and some of them are follows below. Using json.loads() and dict.items() method Using json.loads with a Manual Tuple Construction ...

Read More

Check if one list is subset of other in Python

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 14-Oct-2024 6K+ Views

Python provides various methods to check if one list is a subset of another like 'all()' function and also by using 'issubset()' function to perform this check effectively. The three primary approaches used for checking if one list is a subset of another in Python are as follows. all() function : Checks if all elements in list of an iterable are true. issubet() method : Used in python sets for collecting of unique elements. intersection() method : ...

Read More

Python – Sort grouped Pandas dataframe by group size?

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 09-Oct-2024 10K+ Views

To group Pandas data frame, we use groupby(). To sort grouped data frames in ascending or descending order, use sort_values(). The size() method is used to get the data frame size. Steps Involved The steps included in sorting the panda's data frame by its group size are as follows. Importing the panda's library and Creating a Pandas dataframe. Grouping the columns by using the groupby() function and sorting the ...

Read More

File Objects in Python?

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 09-Oct-2024 6K+ Views

In Python, whenever we try to read or write files we don’t need to import any library as it’s handled natively. The open() function opens a file and returns a file object. The file objects contain methods and attributes which latter can be used to retrieve information or manipulate the file you opened. File Operations The file is a named location on the disk to store related information, as the file is having some name and location, it is stored in the hard disk. In Python, file operation is performed in the following order - ...

Read More

How to Merge all CSV Files into a single dataframe – Python Pandas?

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 09-Oct-2024 17K+ Views

To merge all CSV files, use the GLOB module. The os.path.join() method is used inside the concat() to merge the CSV files together. Some of the common methods we can use to merge multiple CSV Files into a single dataframe are as follows - os.path.join() and glob Merging CSV Files with glob Pattern ...

Read More

Find Circles in an Image using OpenCV in Python

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 09-Oct-2024 8K+ Views

The OpenCV platform provides a cv2 library for Python. This can be used for various shape analyses which is useful in Computer Vision. To identify the shape of a circle using OpenCV we can use the cv2.HoughCircles() function. It finds circles in a grayscale image using the Hough transform. Common Approaches Some of the common methods to find circles in an image using OpenCV are as follows - Circle detection using Hough transform OpenCV ...

Read More

Fraction module in Python

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 09-Oct-2024 7K+ Views

In Python, the Fraction module supports rational number arithmetic. Using this module, we can create fractions from integers, floats, decimals, and other numeric values and strings. The constructor of this class accepts Numerator and Denominator as parameters and creates Fractions from them. The default value of the numerator is 0 and the default value of the denominator is 1. The cost raises ZeroDivisionError when the denominator is 0. Creating Fraction Instances At first, we will see how the class can create fractions using Numerator and Denominator. Example from fractions import Fraction as frac print(frac(45, 54)) print(frac(12, 47)) print(frac(0, 15)) ...

Read More

Generate pseudo-random numbers in Python

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 09-Oct-2024 4K+ Views

Many computer applications need random numbers to be generated. However, none of them generate an actual random number. Python, like any other programming language, uses a pseudo-random generator. Python’s random generation is based on the Mersenne Twister algorithm that produces 53-bit precision floats. The technique is fast and thread-safe but not suitable for cryptographic purposes. Python’s standard library contains the random module which defines various functions for handling randomization. The following functions handle random integer number generation. random.seed() − This function initializes the random number generator. ...

Read More

Program to find sum of odd elements from list in Python

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 04-Oct-2024 7K+ Views

In Python you can find the sum of all odd elements in an existing List one of the following ways - Using List Comprehension Using a Loop Using filter() Function Using List Comprehension The List Comprehension method allows us to create a new list ...

Read More
Showing 61–70 of 80 articles
« Prev 1 4 5 6 7 8 Next »
Advertisements