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.

  • Returns all the elements of a list except the last one.

  • List intersection

    Python, List

    Returns a list of elements that exist in both lists.

  • Checks if the elements of the first list are contained in the second one regardless of order.

  • Last list element

    Python, List

    Returns the last element in a list.

  • Palindrome

    Python, String

    Checks if the given string is a palindrome.

  • List union

    Python, List

    Returns every element that exists in any of the two lists once.

  • Add days to date

    Python, Date

    Calculates the date of n days from the given date.

  • Clamp number

    Python, Math

    Clamps num within the inclusive range specified by the boundary values.

  • Number in range

    Python, Math

    Checks if the given number falls within the given range.

  • Number is prime

    Python, Math

    Checks if the provided integer is a prime number.

  • Pad number

    Python, String

    Pads a given number to the specified length.

  • Byte size of string

    Python, String

    Returns the length of a string in bytes.

  • Capitalize every word

    Python, String

    Capitalizes the first letter of every word in a string.

  • Repeat string

    Python, String

    Generates a string with the given string value repeated n number of times.

  • Factorial

    Python, Math

    Calculates the factorial of a number.