Sayan-Maity / Python-Utility-functions

Tons of Python Utility functions required for Dev purposes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Python-Utility-functions

Tons of Python Utility functions required for Dev purposes

Contribute and add your secret script.

📝 NOTES

Get All the files in a directory

Script: Get All Files in a dir

def get_all_files_in_dir(dir_path, file_ext):
    """
    Get all files in a directory with a specific extension
    :param dir_path: Directory path
    :param file_ext: File extension
    :return: List of files
    """
    return [f for f in listdir(dir_path) if isfile(join(dir_path, f)) and f.endswith(file_ext)]

Flatten all iterables (lists, tuples, dicts, etc), into one lazy generator-stream

Script: Flatten all iterables

def flatten(l):
    """
    Flatten all iterables (lists, tuples, dicts, etc), into one lazy generator-stream
    """
    if isinstance(l, dict):
        l = l.items()
    for el in l:
        if isinstance(el, collections.Iterable) and not isinstance(el, basestring):
            for sub in flatten(el):
                yield sub
        else:
            yield el

Members

Forkers repo roster for @Prasundas99/Python-Utility-functions

Growth during Hacktoberfest 2022

Contributor over time

About

Tons of Python Utility functions required for Dev purposes

License:MIT License


Languages

Language:Python 100.0%