# Confusion regarding a rule in The Zen of Python

**URL:** <https://discuss.python.org/t/confusion-regarding-a-rule-in-the-zen-of-python/15927>\
**Category:** Python Help\
**Created:** [May 23, 2022, 5:59am UTC](https://discuss.python.org/t/confusion-regarding-a-rule-in-the-zen-of-python/15927 "2022-05-23T05:59:46Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![aivarpaalberg](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/aivarpaalberg/32/9457_2.png) [@aivarpaalberg](https://discuss.python.org/u/aivarpaalberg)\
**Post date:** [May 23, 2022, 6:55am UTC](https://discuss.python.org/t/confusion-regarding-a-rule-in-the-zen-of-python/15927/2 "2022-05-23T06:55:05Z")

</div>

I think that [PEP 584 – Add Union Operators To dict](https://peps.python.org/pep-0584/) addresses it (i.e. dictionary part and in general) pretty neatly:

### [Only One Way To Do It](https://peps.python.org/pep-0584/#only-one-way-to-do-it)

Dict union will violate the Only One Way koan from the Zen.

#### [Response](https://peps.python.org/pep-0584/#id3)

There is no such koan. “Only One Way” is a calumny about Python originating long ago from the Perl community.

### [More Than One Way To Do It](https://peps.python.org/pep-0584/#more-than-one-way-to-do-it)

Okay, the Zen doesn’t say that there should be Only One Way To Do It. But it does have a prohibition against allowing “more than one way to do it”.

#### [Response](https://peps.python.org/pep-0584/#id4)

There is no such prohibition. The “Zen of Python” merely expresses a _preference_ for “only one _obvious_ way”:

There should be one-- and preferably only one --obvious way to do it.

The emphasis here is that there should be an obvious way to do “it”. In the case of dict update operations, there are at least two different operations that we might wish to do:

- _Update a dict in place_ : The Obvious Way is to use the `update()` method. If this proposal is accepted, the `|=` augmented assignment operator will also work, but that is a side-effect of how augmented assignments are defined. Which you choose is a matter of taste.
- _Merge two existing dicts into a third, new dict_ : This PEP proposes that the Obvious Way is to use the `|` merge operator.

In practice, this preference for “only one way” is frequently violated in Python. For example, every `for` loop could be re-written as a `while` loop; every `if` block could be written as an `if` / `else` block. List, set and dict comprehensions could all be replaced by generator expressions. Lists offer no fewer than five ways to implement concatenation:

- Concatenation operator: `a + b`
- In-place concatenation operator: `a += b`
- Slice assignment: `a[len(a):] = b`
- Sequence unpacking: `[*a, *b]`
- Extend method: `a.extend(b)`

We should not be too strict about rejecting useful functionality because it violates “only one way”.

---

_[View the full topic](https://discuss.python.org/t/confusion-regarding-a-rule-in-the-zen-of-python/15927)._
