
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 10476 Articles for Python

6K+ Views
Lists are the most widely used data collectios in python. We may come across situation when we need to know if the given list is already sorted or not. In this article we will see the approaches to achieve this.With sortWe take a copy of the given list, apply sort function to it and store that copy as a new list. Then we compare it with the original list and check if they are equal or not.Example Live DemolistA = [11, 23, 42, 51, 67] #Given list print("Given list : ", listA) listA_copy = listA[:] # Apply sort to copy listA_copy.sort() ... Read More

3K+ Views
Depending on the needs of our data analysis we may need to check for presence of sequential numbers in a python data container. In the below programs we find out if among the elements of Alist, there are any consecutive numbers.With range and sortedThe sorted function will rearrange the elements of the list in a sorted order. We then apply the range function taking the lowest and highest numbers form the list using min and max functions. We store the results of above operations in two lists and compare them for equality.Example Live DemolistA = [23, 20, 22, 21, 24] sorted_list ... Read More

567 Views
We sometimes need to check if a required string can be formed from many number of strings that are present in a list. It also should not matter in what order the strings are present in the list which have to be joined to get the required string.With permutationsFrom itertools we can use the permutations function which will give us the possible combinations of the strings in the list in various order. As soon as a given combination matches the required string, we conclude that the string can be formed.Example Live Demofrom itertools import permutations chk_str = 'balloon' Alist = ... Read More

2K+ Views
During data analysis using python, we may need to verify if a couple of values exist as keys in a dictionary. So that the next part of the analysis can only be used with the keys that are part of the given values. In this article we will see how this can be achieved.With Comparison operatorsThe values to be checked are put into a set. Then the content of the set is compared with the set of keys of the dictionary. The >= symbol indicates all the keys from the dictionary are present in the given set of values.Example Live DemoAdict ... Read More

1K+ Views
Python Tuples can be nested. We can have a tuple whose elements are also tuples. In this article we will see how to find out if a given value is present as an element in a tuple of tuples.With anyThe any function can be used to check if a given value is present as an element in any of the subtuples that are present in the tuple with help of for loop. We put the entire condition for checking in an if and else clause.Example Live DemoAtuple = [('Mon', 10), ('Tue', 8), ('Wed', 8), ('Thu', 5)] #Given tuple print("Given tuple: ... Read More

2K+ Views
Lists can be nested, means the elements of a list are themselves lists. In this article we will see how to find out if a given element is present in the sublist which are themselves elements in the bigger list.With anyWe first search if an element is present in the sublist and if the sublist is present in the list. If anyof this is true we can say that the element is present in the list.Example Live DemolistA = [[-9, -1, 3], [11, -8], [-4, 434, 0]] search_element = -8 # Given list print("Given List :", listA) print("Element to ... Read More

840 Views
Lists can be nested, means the elements of a list are themselves lists. In this article we will see how to find out if a given list is present as an element in the outer bigger list.With inThis is a very simple and straight forward method. We use the in clause just to check if the inner list is present as an element in the bigger list.Example Live DemolistA = [[-9, -1, 3], [11, -8], [-4, 434, 0]] search_list = [-4, 434, 0] # Given list print("Given List :", listA) print("list to Search: ", search_list) # Using in if ... Read More

604 Views
Lists are very frequently used data container in Python. While using lists we may come across a situation where the elements of the list maybe a sequence of numbers. We can add this sequence of numbers to a list using many Python functions. In this article we will explore different ways of doing that.With range and extendThe extent function allows us to increase the number of elements in a list. Will use the range function and apply extend to the list so that all the required sequence of numbers are added at the end of the list.Example Live DemolistA = [55, ... Read More

2K+ Views
Depending on the need of the program we may an requirement of assigning the values in a list to many variables at once. So that they can be further used for calculations in the rest of the part of the program. In this article we will explore various approaches to achieve this.Using for inThe for loop can help us iterate through the elements of the given list while assigning them to the variables declared in a given sequence.We have to mention the index position of values which will get assigned to the variables.Example Live DemolistA = ['Mon', ' 2pm', 1.5, '11 ... Read More

8K+ Views
For various data analysis work in python we may be needed to combine many python lists into one list. This will help processing it as a single input list for the other parts of the program that need it. It provides performance gains by reducing number of loops required for processing the data further.Using + operatorThe + operator does a straight forward job of joining the lists together. We just apply the operator between the name of the lists and the final result is stored in the bigger list. The sequence of the elements in the lists are preserved.Example Live DemolistA ... Read More