- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10807 Articles for Python
244 Views
In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a list input , we need to find the sum of absolute difference between all pairs in a list.Enumerate() method adds a counter to an iterable and returns it in a form of enumerate object type.In this method, we have a list ‘diffs’ which contains the absolute difference.We use two loops having two variables initialized . One is to iterate through the counter and another for the list element. In every iteration, we check whether the elements are similar or not.If not, ... Read More
213 Views
In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven list input, we need to find the largest numbers in the given list .Here we will discuss two approachesUsing sorting techniquesUsing built-in max() functionApproach 1 − Using built-in sort() functionExample Live Demolist1 = [18, 65, 78, 89, 90] list1.sort() # main print("Largest element is:", list1[-1])OutputLargest element is: 90Approach 2 − Using built-in max() functionExample Live Demolist1 = [18, 65, 78, 89, 90] # main print("Largest element is:",max(list1))OutputLargest element is: 90ConclusionIn this article, we learnt about the approach to find largest number in a list.
873 Views
In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a number we need to convert into a binary number.Approach 1 − Recursive SolutionDecToBin(num): if num > 1: DecToBin(num // 2) print num % 2Exampledef DecimalToBinary(num): if num > 1: DecimalToBinary(num // 2) print(num % 2, end = '') # main if __name__ == '__main__': dec_val = 35 DecimalToBinary(dec_val)Output100011All the variables and functions are declared in the global scope as shown below −Approach 2 − Built-in SolutionExample Live Demodef ... Read More
204 Views
In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven an array input of integers, we need to find whether it’s possible to make an integer using all the digits available in these numbers such that it would be divisible by 3.Here we will generate a function that will take two arguments namely the array of integers and the length of the array.The implementation given below works on the concept from the mental mathematics. Here we observe that a number is divisible by 3 if the sum of the digits are divisible ... Read More
6K+ Views
In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a string input, we need to generate a Python program to check whether that string is Pangram or not.A pangram is a sentence/ series of words which contains every letter in the English Alphabets collection.Now let’s see how we can solve the problemWe will use a loop that checks whether each character present in the input string belongs to the alphabet set or not which we will declare manually .The implementation of the approach above is given by −Example Live Demoimport string def ... Read More
6K+ Views
In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a string input, we need to create a python function to check whether it is a palindrome or not.A string is referred to be palindrome if the reverse of the string is identical with string.We can do this by two methods −Reversal by slicingComparison via negative indexingHere we will be learning reversal pf string bu the help of slicing.To reverse a string by th method of slicing specify the following statement −Str[ : : -1 ]Where the start and end parameters are ... Read More
986 Views
In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven an array input Arr containing n integers. We need to check whether the input array is Monotonic in nature or not.An array is said to be monotonic in nature if it is either continuously increasing or continuously decreasing.Mathematically,An array A is continuously increasing if for all i
408 Views
In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a sring input, we need to find whether a string contains all unique characters or not.ApproachWe will create an array of boolean values, where the variable flag at the index i indicates that whether character i in the alphabet is contained in the string or not.The second time we encounter this character we can immediately return false as string characters is no longer unique.We can also return false if the string length exceeds the value of number of unique characters presnt in ... Read More
1K+ Views
In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven an integer n , we need to check that the given integer is an armstrong number.A positive integer is called an Armstrong number of order n ifabcd... = a^n + b^n + c^n + d^n + …Here we will be discussing the brute-force approach for an armstrong number of 3 digits and hence of order three.To check the armstrong number of order n we need to replace 3 by the corresponding order value in line number 7.Now let’s see the implementation −Example Live ... Read More
575 Views
In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a positive integer N as input . We need to compute the value of 12 + 22 + 32 + ….. + N2.Problem statement:This can be solved by two methodsMultiplication addition arithmeticUsing mathematical formulaApproach 1: Multiplication & Addition ArithmeticHere we run a loop from 1 to n and for each i, 1