osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Please improve these comprehensions (was meaning of [ ])


On Wednesday, September 6, 2017 at 5:59:17 PM UTC+5:30, nopsidy wrote:
> https://www.youtube.com/watch?v=pNe1wWeaHOU&list=PLYI8318YYdkCsZ7dsYV01n6TZhXA6Wf9i&index=1
> Thank you,
> -Alex Goretoy
> http://launchpad.net/~a1g

You (Alex) are top-posting. I am not fussy. But others here can be
In any case thanks for quoting Stefan's post which I would not see otherwise

> 
> 
> On Wed, Sep 6, 2017 at 7:22 PM, Stefan Ram  wrote:
> > Rustom Mody  writes:
> >>Because the abstract idea of a permutation is a list (sequence)
> >
> >   Traditional mathematical books (which are not influenced by
> >   computer programming terminology) often use "n-tuple"
> >   (or "sequence") instead of "list" IIRC.
> >
> >   It is important to note that - according to me - a Python
> >   data structure with the same /name/ as a mathematical concept
> >   does not always have to be the best way to implement that
> >   mathematical concept. E.g., sometimes a Python list might be
> >   the best way to implement a mathematical tuple, or a Python
> >   tuple may be the best way to implement a mathematical set.

I came to the conclusion and said more or less what you are saying Stefan?
when programmer hat is on. viz that the simplest solution (all lists) is 
probably the way to go.

I've taught this (with the simple list-solution) many times over decade(s)

Then this time I thought: "Hey! Python now has sets. And even set-
comprehensions!  Maybe the solution could be more sparkling clean if I switch
from lists to sets?"

However every effort of mine was clumsy and unsatisfactory.

So thought of asking if I am missing something? Evidently not
- the set data type does not nest ? {1,2} possible {{1,2},{3,4}} not
- the frozenset datatype is (pragmatically) incomplete ? no clean way to 
  separate an element from a (frozen)set

So all in all too many hoops to jump through
[Greg talked of efficiency ? not my primary concern (here)]

PS As said I do not see your posts (Stefan) unless someone quotes them