Pavitra has Published 177 Articles

Python program to insert an element into sorted list

Pavitra

Pavitra

Updated on 24-Dec-2019 05:30:25

926 Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given a list, we need to insert an element in a list without changing sorted orderThere are two approaches as discussed below−Approach 1: The brute-force methodExample Live Demodef insert(list_, n):    # search ... Read More

Python program to get all subsets of a given size of a set

Pavitra

Pavitra

Updated on 24-Dec-2019 05:26:57

512 Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given a set, we need to list all the subsets of size nWe have three approaches to solve the problem −Using itertools.combinations() methodExample Live Demo# itertools module import itertools def findsubsets(s, n):   ... Read More

Python Program to find whether a no is power of two

Pavitra

Pavitra

Updated on 24-Dec-2019 05:18:26

2K+ Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given a number, we need to check that the number is a power of two or not.We can solve this using two approaches as discussed below.Approach 1: Taking the log of the ... Read More

Python program to find the smallest number in a list

Pavitra

Pavitra

Updated on 23-Dec-2019 09:30:14

222 Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given al list, we need to display the smallest number available in the listHere we can either sort the list and get the smallest element or use the built-in min() function ... Read More

Python program to find the largest number in a list

Pavitra

Pavitra

Updated on 23-Dec-2019 08:09:45

874 Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given a list, we need to calculate the largest element of the list.Here we will take the help of built-in functions to reach the solution of the problem statementUsing sort() functionExample# list ... Read More

Python Program to find the largest element in an array

Pavitra

Pavitra

Updated on 23-Dec-2019 08:07:18

909 Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given an array, we need to calculate the largest element of the array.Here we use the bruteforce approach in which we compute the largest element by traversing the whole loop and get ... Read More

Count upper and lower case characters without using inbuilt functions in Python program

Pavitra

Pavitra

Updated on 23-Dec-2019 07:54:17

465 Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given a string, we need to count the number of uppercase and lowercase characters present in the string without using the inbuilt functionThis can be easily solved by using islower() and isupper() ... Read More

Python Program to convert Kilometers to Miles

Pavitra

Pavitra

Updated on 23-Dec-2019 07:37:08

196 Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given distance in kilometers and we need to convert it into milesAs we know that 1 kilometer equals 0.62137 miles.Formula UsedMiles = kilometer * 0.62137Now let’s observe the concept in the implementation ... Read More

Python program to convert hex string to decimal

Pavitra

Pavitra

Updated on 23-Dec-2019 07:35:02

337 Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given a hexadecimal string, we need to convert it into its decimal equivalent.We have two approaches to solve the problem−Brute-force ApproachUsing Built-in moduleBrute-Force MethodHere we take the help of explicit type casting ... Read More

Convert a list to string in Python program

Pavitra

Pavitra

Updated on 23-Dec-2019 07:28:22

156 Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given a list iterable, we need to convert it into a string type iterable.There are four approaches to solve the given problem. Let’s see them one by one−Brute-force ApproachExample Live Demodef listToString(s):   ... Read More

Advertisements