meaning of [ ]
Rustom Mody
rustompmody at gmail.com
Mon Sep 4 10:50:49 EDT 2017
On Monday, September 4, 2017 at 7:57:23 PM UTC+5:30, Rustom Mody wrote:
> On Monday, September 4, 2017 at 6:36:11 PM UTC+5:30, Ben Bacarisse wrote:
> > But [p for p in sys.path] is a list and "set-builder" notation is used
> > for sets. Order is crucial for sys.path. You say exactly that below so
> > I don't see how referring to sets helps anyone understand lists.
>
> Clearly if the question was of *sets* vs *lists* the distinction is at least as
> crucial, maybe even more so than the similarity.
> The OP-question here however is one about comprehensions and it appears without
> the questioner realizing that — as Peter's answer showed
>
> See the very first line of this:
> https://en.wikipedia.org/wiki/List_comprehension
> “List comprehension follows the form of the mathematical set-builder notation (set comprehension)”
>
> ie its both historically and structurally linked
> IOW emphasising the incidental sequential nature of the computation
> at the cost of the fundamental structure-preserving nature of the concept
Incomplete; I meant to say:
ie its both historically and structurally linked.
IOW emphasising the incidental sequential nature of the computation
at the cost of the fundamental structure-preserving nature of the concept
seems to be some ()*&^$W# behavior on the part of people instructing python
The essential meaning of comprehensions is the following diagrams
not the for-loop implementation
If l is
[x₁, x₂,… xₙ ]
[f(x) for x in l]
means this picture:
[x₁, x₂,… xₙ ]
↓ ↓… ↓
[f(x₁), f(x₂),… f(xₙ)]
Likewise
If s is
{x₁, x₂,… xₙ}
{f(x) for x in s}
means this picture:
{x₁, x₂, … xₙ}
↓ ↓ … ↓
{f(x₁), f(x₂),… f(xₙ)}
More information about the Python-list
mailing list