- 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 10784 Articles for Python
5K+ Views
In Python Programming Language, Length is the concept of calculating the entire range of the string that begins from the first character of the string till the last character of the string. Printing and calculating even length in a string is a basic exercise in the programing language. In this tutorial, we will learn about the solution and approach to find out all words in a string having even length. A number is considered odd if it divides by 2 evenly, i.e. leaving no remainder. This property should hold for the length of the words we need. So the ... Read More
![Pavitra](https://www.tutorialspoint.com/articles/images/user_icon.png)
749 Views
In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a range, we need to print all the odd numbers in the given range.The brute-force approach is discussed below −Here we apply a range-based for loop which provides all the integers available in the input interval.After this, a check condition for odd numbers is applied to filter all the even numbers.This approach takes O(n) + constant time of comparison.Now let’s see the implementation below −Examplestart, end = 10, 29 # iteration for num in range(start, end + 1): # check ... Read More
![Pavitra](https://www.tutorialspoint.com/articles/images/user_icon.png)
1K+ Views
In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a range, we need to print all the even numbers in the given range.The brute-force approach is discussed below −Here we apply a range-based for loop which provides all the integers available in the input interval.After this, a check condition for even numbers is applied to filter all the odd numbers.This approach takes O(n) + constant time of comparison.Now let’s see the implementation below −Examplestart, end = 10, 29 # iteration for num in range(start, end + 1): # check ... Read More
![Pavitra](https://www.tutorialspoint.com/articles/images/user_icon.png)
156 Views
In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a number n, we need to check whether the given number is a power of two.ApproachContinue dividing the input number by two, i.e, = n/2 iteratively.We will check In each iteration, if n%2 becomes non-zero and n is not 1 then n is not a power of 2.If n becomes 1 then it is a power of 2.Let’s see the implementation below −Exampledef isPowerOfTwo(n): if (n == 0): return False while (n != 1): ... Read More
![Pavitra](https://www.tutorialspoint.com/articles/images/user_icon.png)
408 Views
In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven an input string we need to find the most occurring character and its count.ApproachCreate a dictionary using Counter method having strings as keys and their frequencies as values.Find the maximum occurrence of a character i.e. value and get the index of it.Now let’s see the implementation below −Examplefrom collections import Counter def find(input_): # dictionary wc = Counter(input_) # Finding maximum occurrence s = max(wc.values()) i = wc.values().index(s) print (wc.items()[i]) # Driver program if __name__ ... Read More
![Pavitra](https://www.tutorialspoint.com/articles/images/user_icon.png)
2K+ Views
In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a dictionary, we need to find the three highest valued values and display them.Approach 1 − Using the collections module ( Counter function )Example Live Demofrom collections import Counter # Initial Dictionary my_dict = {'t': 3, 'u': 4, 't': 6, 'o': 5, 'r': 21} k = Counter(my_dict) # Finding 3 highest values high = k.most_common(3) print("Dictionary with 3 highest values:") print("Keys: Values") for i in high: print(i[0], " :", i[1], " ")OutputDictionary with 3 highest values: Keys: Values r : 21 t ... Read More
![Pavitra](https://www.tutorialspoint.com/articles/images/user_icon.png)
433 Views
In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven an list as an input, we need to compute the sum of the given list.Here we have two approaches to consider i.e. using built-in function & using the brute-force approach.Approach 1 − Using built-in functionExample Live Demo# main arr = [1, 2, 3, 4, 5] ans = sum(arr) print ('Sum of the array is ', ans)Output15All the variables & functions are declared in the global scope and are shown below.Approach 2 − Using brute-force methodExample Live Demototal = 0 # creating a list list1 ... Read More
![Pavitra](https://www.tutorialspoint.com/articles/images/user_icon.png)
772 Views
In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven an array as an input, we need to compute the sum of the given array.Here we may follow the brute-force approach i.e. traversing over a list and adding each element to an empty sum variable. Finally, we display the value of the sum.We can also perform an alternate approach using built-in sum function as discussed below.Example# main arr = [1, 2, 3, 4, 5] ans = sum(arr, n) print ('Sum of the array is ', ans)Output15 All the variables & functions are ... Read More
![Pavitra](https://www.tutorialspoint.com/articles/images/user_icon.png)
263 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
![Pavitra](https://www.tutorialspoint.com/articles/images/user_icon.png)
234 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.