meaning of [ ]

Steve D'Aprano steve+python at pearwood.info
Mon Sep 4 08:57:58 EDT 2017


On Mon, 4 Sep 2017 01:36 pm, Rustom Mody wrote:

> Tsk tsk the confusioning continues

Rustom, it is generally considered that we should do our best to *reduce*
confusion, not increase it. *wink*

> Rewrite
> [p for p in sys.path]
> as
> [p | p ∈ sys.path]
> 
> Is that clearer?

No. What is "|" in that supposed to mean?

- a Unix pipe? 
- bitwise "or"?
- logical "or"?
- an opening absolute value delimiter, |x|, missing the closing one?
- or the other way around?
- half of a "parallel" symbol?
- half of a bra-ket symbol?
- the divides operator? not division, divides, as in "5 divides 10" = 5|10
- Sheffer stroke (nand)?
- conditional probability?
- the dental click in Khoisan languages?

or one of about twenty or thirty other meanings. Which one do you intend, and
what makes you believe that the OP would guess the same one?


> As Peter pointed out this is a no-op
> ie
> [p for p in sys.path]
>
> could be written as
> list(sys.path)

That's not what "no-op" means. If it returns a result, it isn't a no-op.

> [Not sure why he didnt say just sys.path]

Because sys.path returns the same list, [p for p in sys.path] returns a new
list.



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list