Tag: List
Python : Check if a list contains all the elements of another list
In this article we will discuss if a list contains all or any elements of another list. Suppose we have have two list i.e. Advertisements # List of string list1 = [‘Hi’ , ‘hello’, ‘at’, ‘this’, ‘there’, ‘from’] # List of string list2 = [‘there’ , ‘hello’, ‘Hi’] Check if list1 contains all elements of …
Python : Check if a list contains all the elements of another listRead More
Python : How to add an element in list ? | append() vs extend()
In this article we will discuss how to add element in an existing list using different techniques. Adding item in list using list.append() list.append(item) It adds the item at the end of list. Advertisements For example, we have a list of string i.e. # List of string wordList = [‘hi’, ‘hello’, ‘this’, ‘that’, ‘is’, ‘of’] …
Python : How to add an element in list ? | append() vs extend()Read More
Python: How to sort a list of tuples by 2nd Item using Lambda Function or Comparator
In this article we will discuss how to sort a list of tuple using 2nd or i th item of tuple. Suppose we have a list of tuple i.e. words and thier frequency count, Advertisements # List of tuples i.e. word and its frequency count wordFreq = [ (‘the’ , 34) , (‘at’ , 23), …
Python: How to sort a list of tuples by 2nd Item using Lambda Function or ComparatorRead More
Python : How to Sort a list of strings ? | list.sort() Tutorial & Examples
In this article we will discuss how to sort a list of string by, By Alphabetical Order By Reverse Alphabetical Order By String Length By Numeric Order list.sort() list provides a member function sort(). It Sorts the elements of list in low to high order i.e. if list is of numbers then by default they will …
Python : How to Sort a list of strings ? | list.sort() Tutorial & ExamplesRead More
Python : How to create a list and initialize with same values
In this article we will discuss how to create a list and initialise with same values. Creating a list of same values by [] and multiply Suppose we want to create a list of strings, which contains 20 same strings i.e. ‘Hi’ Advertisements [‘Hi’, ‘Hi’, ‘Hi’, ‘Hi’, ‘Hi’, ‘Hi’, ‘Hi’, ‘Hi’, ‘Hi’, ‘Hi’, ‘Hi’, ‘Hi’, …
Python : How to create a list and initialize with same valuesRead More
Python : How to Iterate over a list ?
In this article we will discuss different ways to iterate over a list. Iterate over the list using for-in loop Its easies solution to iterate over the list i.e. Advertisements ”’ Iterate over the list using for loop ”’ for word in wordList: print(word) Output hi hello this that is of Iterate over the list …
Python : How to Insert an element at specific index in List ?
In this article we will discuss how to insert an element in list at specific position. Inserting an element in list at specific index using list.insert() In python list provides a member function insert() i.e. Advertisements list.insert(position, element) It accepts a position and an element and inserts the element at given position in the list. …
Python : How to Insert an element at specific index in List ?Read More
Python : How to create a list of all the Values in a dictionary ?
In this article we will discuss how to create a list of all the values in dictionary. Suppose we have a dictionary of string and integers i.e. Advertisements # Dictionary of string and int wordFreqDic = { “Hello”: 56, “at” : 23 , “test” : 43, “this” : 2, “here” : 23, “city” : 2, …
Python : How to create a list of all the Values in a dictionary ?Read More
python : How to create a list of all the keys in the Dictionary ?
In this article we will discuss how to create a list of all keys in a dictionary. Suppose we have a dictionary of string and integers i.e. Advertisements # Dictionary of string and int wordFreqDic = { “Hello”: 56, “at” : 23 , “test” : 43, “this” : 78, “here” : 18, “city” : 2, …
python : How to create a list of all the keys in the Dictionary ?Read More
Python : How to Get List of all empty Directories ?
In this article we will discuss how to get list of all empty directories. Python’s os module provides a function to iterate over a directory tree i.e. Advertisements os.walk(path) It iterates of the directory tree at give path and for each directory or sub directory it returns a tuple containing, (<Dir Name> , <List of …
Python : How to Get List of all empty Directories ?Read More