Skip to content

Commit

Permalink
Update naturallist docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk authored Oct 2, 2024
1 parent a4efc82 commit dfc4886
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/humanize/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,30 @@

from __future__ import annotations

from collections.abc import Iterable
from typing import Any

__all__ = ["naturallist"]


def naturallist(items: list[Any]) -> str:
def naturallist(items: Iterable[Any]) -> str:
"""Natural list.
Convert a list of items into a human-readable string with commas and 'and'
Convert an iterable of items into a human-readable string with commas and 'and'.
Args:
items (list): A list of strings
Returns:
str: A string with commas and 'and' in the right places
Examples:
>>> naturallist(["one", "two", "three"])
'one, two and three'
>>> naturallist(["one", "two"])
'one and two'
>>> naturallist(["one"])
'one'
Args:
items (Iterable): An iterable of items.
Returns:
str: A string with commas and 'and' in the right places.
"""
if len(items) == 1:
return str(items[0])
Expand Down

0 comments on commit dfc4886

Please sign in to comment.