Python Snippets

The Python snippet collection contains helper functions for Python 3.6. It includes utilities for most common data types, such as primitivies, lists, dictionaries and date objects.

  • String to slug

    Converts a string to a URL-friendly slug.

    Python, String · Oct 25, 2020

  • Spread list

    Flattens a list, by spreading its elements into a new list.

    Python, List · Sep 15, 2020

  • Lists to dictionary

    Combines two lists into a dictionary, using the first one as the keys and the second one as the values.

    Python, List · Nov 2, 2020

  • Tip: Avoid using bare except in Python

    It's generally not a good idea to use bare except clause in Python, but do you know why?

    Python, Error · Feb 20, 2022

  • What is the difference between Python's equality operators?

    Python provides two distinct comparison operators for different task. Stop mixing them up using this quick guide.

    Python, Type · Jun 12, 2021

  • Understanding Python's slice assignment

    Learn everything you need to know about Python's slice assignment with this handy guide.

    Python, List · Jun 12, 2021

  • Deep flatten list

    Deep flattens a list.

    Python, List · Dec 29, 2020

  • Dictionary to list

    Converts a dictionary to a list of tuples.

    Python, Dictionary · Nov 2, 2020

  • Execute function for each list element

    Executes the provided function once for each list element.

    Python, List · Sep 15, 2020

  • Greatest common divisor

    Calculates the greatest common divisor of a list of numbers.

    Python, Math · Sep 15, 2020

  • All indexes of value

    Returns a list of indexes of all the occurrences of an element in a list.

    Python, List · Oct 11, 2020

  • String is anagram

    Checks if a string is an anagram of another string (case-insensitive, ignores spaces, punctuation and special characters).

    Python, String · Nov 2, 2020

  • Dictionary keys

    Creates a flat list of all the keys in a flat dictionary.

    Python, Dictionary · Nov 2, 2020

  • Least common multiple

    Returns the least common multiple of a list of numbers.

    Python, Math · Nov 2, 2020

  • Powerset

    Returns the powerset of a given iterable.

    Python, Math · Nov 2, 2020