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.

  • Average

    Calculates the average of two or more numbers.

    Python, Math · Nov 2, 2020

  • Days ago

    Calculates the date of n days ago from today.

    Python, Date · Oct 28, 2020

  • Date difference in days

    Calculates the day difference between two dates.

    Python, Date · Oct 28, 2020

  • Days from now

    Calculates the date of n days from today.

    Python, Date · Oct 28, 2020

  • Fibonacci

    Generates a list, containing the Fibonacci sequence, up until the nth term.

    Python, Math · Nov 2, 2020

  • Find key of value

    Finds the first key in the provided dictionary that has the given value.

    Python, Dictionary · Nov 2, 2020

  • Date is weekday

    Checks if the given date is a weekday.

    Python, Date · Nov 2, 2020

  • Date is weekend

    Checks if the given date is a weekend.

    Python, Date · Nov 2, 2020

  • Key in dictionary

    Checks if the given key exists in a dictionary.

    Python, Dictionary · Oct 16, 2020

  • 3 ways to swap two variables in Python

    Learn 3 easy ways to swap the values of two variables in Python.

    Python, Variables · Nov 7, 2021

  • Unique elements in list

    Returns the unique elements in a given list.

    Python, List · Sep 15, 2020

  • Apply function when true

    Tests a value, x, against a testing function, conditionally applying a function.

    Python, Function · Nov 9, 2020

  • Check if list elements are identical

    Checks if all elements in a list are equal.

    Python, List · Oct 11, 2020

  • Cast to list

    Casts the provided value as a list if it's not one.

    Python, List · Nov 2, 2020

  • Count occurrences

    Counts the occurrences of a value in a list.

    Python, List · Jan 9, 2021