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.

  • hex_to_rgb

    Python, String

    Converts a hexadecimal color code to a tuple of integers corresponding to its RGB components.

  • Learn two ways to format a string in Python with this quick tip.

  • rgb_to_hex

    Python, String

    Converts the values of RGB components to a hexadecimal color code.

  • to_roman_numeral

    Python, Math

    Converts an integer to its roman numeral representation. Accepts value between 1 and 3999 (both inclusive).

  • Learn of the two different way to convert a string to lowercase in Python and understand when you should use each one with this quick guide.

  • kebab

    Python, String

    Converts a string to kebab case.

  • longest_item

    Python, List

    Takes any number of iterable objects or objects with a length property and returns the longest one.

  • words

    Python, String

    Converts a given string into a list of words.

  • camel

    Python, String

    Converts a string to camelcase.

  • snake

    Python, String

    Converts a string to snake case.

  • capitalize

    Python, String

    Capitalizes the first letter of a string.

  • decapitalize

    Python, String

    Decapitalizes the first letter of a string.

  • split_lines

    Python, String

    Splits a multiline string into a list of lines.

  • is_anagram

    Python, String

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

  • slugify

    Python, String

    Converts a string to a URL-friendly slug.