Permutation and Combination in Python Python provides direct methods to find permutations and combinations of a sequence. These methods are present in itertools package. Permutation First import itertools package to implement the permutations method in python. This method takes a
Day: July 24, 2021
Returning Multiple Values in PythonReturning Multiple Values in Python
Returning Multiple Values in Python In Python, we can return multiple values from a function. Following are different ways 1) Using Object: This is similar to C/C++ and Java, we can create a class (in C, struct) to hold multiple
Convert Python List to numpy ArraysConvert Python List to numpy Arrays
Convert Python List to numpy Arrays A list in Python is a linear data structure that can hold heterogeneous elements they do not require to be declared and are flexible to shrink and grow. On the other hand, an array
Python format() functionPython format() function
Python format() function With Python 3.0, the format() method has been introduced for handling complex string formatting more efficiently. This method of the built-in string class provides functionality for complex variable substitutions and value formatting. This new formatting technique is
Python – Using 2D arrays/lists the right wayPython – Using 2D arrays/lists the right way
Python | Using 2D arrays/lists the right way Python provides many ways to create 2-dimensional lists/arrays. However one must know the differences between these ways because they can create complications in code that can be very difficult to trace out.
Python program to check if a string is palindrome or notPython program to check if a string is palindrome or not
Python program to check if a string is palindrome or not Given a string, write a python function to check if it is palindrome or not. A string is said to be palindrome if the reverse of the string is
Defaultdict in PythonDefaultdict in Python
Defaultdict in Python Dictionary in Python is an unordered collection of data values that are used to store data values like a map. Unlike other Data Types that hold only single value as an element, the Dictionary holds key:value pair.
Python – Ways to remove duplicates from listPython – Ways to remove duplicates from list
Python – Ways to remove duplicates from list This article focuses on one of the operations of getting the unique list from a list that contains a possible duplicated. Remove duplicates from list operation has large number of applications and
Python – Get key from value in DictionaryPython – Get key from value in Dictionary
Python | Get key from value in Dictionary Let’s see how to get the key by value in Python Dictionary. Method 1: Using list.index() The index() method returns index of corresponding value in a list. Below is an implementation how
Python StackPython Stack
Stack in Python A stack is a linear data structure that stores items in a Last-In/First-Out (LIFO) or First-In/Last-Out (FILO) manner. In stack, a new element is added at one end and an element is removed from that end only.