« Back to Index

[Python mutate list content and return new list as they’re immutable]

View original Gist on GitHub

Tags: #python

Python mutate list content and return new list as they’re immutable.py

def append_params(urls: list, params: str) -> list:
    """Returns copy of list with modified values.

    Example:
        append_params(["/foo", "/bar", "/baz"], "?id=123")

		-> ["/foo?id=123", "/bar?id=123", "/baz?id=123"]
    """
    return list(map(lambda v: f"{v}{params}", urls))