Tag: Python
Python : Get Current Directory
In this article, we will discuss how to get the current working directory in Python. Python’s os module provides a function to get the current working directory i.e. os.getcwd() It returns a string containing the current working directory. For calling this function we need to import os module i.e. Advertisements import os Let’s understand by …
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
Python : How to check if a directory is empty ?
In this article we will discuss different ways to check if a directory is empty or not. Python’s os module provides a function to get the list of files or folder in a directory i.e. Advertisements os.listdir(path=’.’) It returns a list of all the files and sub directories in the given path. Now if the …
Python : How to get list of files in directory and sub directories
In this article we will discuss different methods to generate a list of all files in directory tree. Creating a list of files in directory and sub directories using os.listdir() Python’s os module provides a function to get the list of files or folder in a directory i.e. Advertisements os.listdir(path=’.’) It returns a list of …
Python : How to get list of files in directory and sub directoriesRead More
Python : How to Remove Duplicates from a List
In this article we will discuss different ways to remove duplicate elements from a list in python. List : Containing duplicate elements : Advertisements [10, 2, 45, 3, 5, 7, 2, 10, 45, 8, 10] List : After removing duplicate elements, [10, 2, 45, 3, 5, 7, 8] Let’s see how to do that, Frequently …
Python : Join / Merge lists ( two or more)
In this article we will discuss different ways to Merge / Join two or more lists in python. Table of Contents Join / Merge two lists in python using + operator. Join / Merge two lists in python using list.extend(). Join / Merge two lists in python using unpacking. Join / Merge two lists in …
Convert list to string in python using join() / reduce() / map()
In this article we will discuss different ways to convert list to string. Convert list to string in python using join() in python In python string class provides a function join() i.e. Advertisements string.join(iterable) join() function accepts an iterable sequence like list or tuple etc as an argument and then joins all items in this …
Convert list to string in python using join() / reduce() / map()Read More
Python : How to remove element from a list by value or Index | remove() vs pop() vs del
In this article we will discuss different ways to remove an elements from list. Remove an element from List by value using list.remove() Python’s list provides a member function to remove an element from list i.e. Advertisements list.remove(value) It removes the first occurrence of given element from the list. For example, Frequently Asked: Convert a …
Python : How to remove element from a list by value or Index | remove() vs pop() vs delRead More
Python : How to remove multiple elements from list ?
In this article we will discuss different ways to remove multiple elements from list. Suppose we have a list of numbers i.e. # List of Numbers listOfnum = [12, 44, 56, 45, 34, 3, 4, 33, 44] Now we want to remove all the numbers from list, which are multiple of 3. Advertisements Remove multiple …
Python : How to remove multiple elements from list ?Read More
Python : How to find keys by value in dictionary ?
In this article we will discuss how to find all keys associated with a given single value or multiple values. Suppose we have a dictionary of words and thier frequency i.e. Advertisements # Dictionary of strings and int dictOfWords = { “hello”: 56, “at” : 23 , “test” : 43, “this” : 97, “here” : …