python-humanize / python-humanize/humanize

Proposal for additional `conjunction` parameter in `natural_list` function

Open
#214 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
756
Forks
148
Avg merge
6d 1h
Merged PRs (30d)
12

Description

Thank you for the new version; natural_list really resolves several issues.

Summary

I would like to propose an enhancement to the natural_list function. Currently, the output for the list [1, 2, 3] is formatted as "1, 2 and 3". I propose adding a parameter that allows users to choose between "and" or "or" in the output.

I checked the documentation and found in #103 that there is interest in implementing something like this issue.

Motivation

This enhancement would provide more flexibility in how lists are presented, particularly in contexts where the choice between "and" and "or" is significant.

Proposed Changes
  1. Introduce a new parameter (e.g., conjunction) to the natural_list function.
  2. Accept boolean values for this parameter:
    • True (default behavior)
    • False
Example Usage

With the proposed change, the usage would look like this:

from humanize import natural_list

print(natural_list([1, 2, 3]))  # Output: "1, 2 and 3"
print(natural_list([1, 2, 3], conjunction=False))  # Output: "1, 2 or 3"
Another Idea

We could also consider adding or and and to the i18n support for multiple languages, but I believe that should be addressed in a separate issue.


I could submit the PR if there's interest, but I'm not sure if conjunction would be the best name for this parameter.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the natural_list implementation and its documentation, then review the related discussion in issue #103. Confirm how the current default output is produced and identify any existing tests or examples for natural_list; done means supporting the requested alternative conjunction while preserving the current default behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
localization
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.