On Mar 27, 7:26 pm, Terry Reedy <tjre...@udel.edu> wrote: > Luis Gonzalez wrote: > > Yes, I know the python approach is to use built-ins. > > But wouldn't it be cool if we could do mydict.values().tolist() > > instead? > > Should we also give every collection a .toset(), .tofrozenset(), > .totuple(), and .todict() method? This way lies the madness of > combinatorial explosion. > > > It would be more regular and intuitive and readable from an OO point > > of view. > > In my opinion, this is backwards. From an OO point of view, instances > of class X should be created by the constructor for that class. That is > where the knowledge of the intermal structure of class X instances > belongs. snip > The stream of object provided by > the iterator is the common means of transferring information.
AKA the iterator protocol. snip > It is part of python basic design. Functions used as functions can be > passed as arguments to functions and used to operator on heterogeneous > collections, as in the example above. > > Terry Jan Reedy I guess there are two arguments for the change. 1. Flat is better than nested. 2. It interferes with the way people read text. The order of events are: First, get the view. Then convert it to a list. Hence, dictA.get_view( ).to_list( ). This may call for a more fundamental change to a programming language than Python should make; and it may have to wait for another generation. It entails that function applications should be of the form '( x )f' instead of 'f( x )', in a pretty general way. I also recognize that natural language and thus human thinking does admit of a certain depth of nesting. English, notably, has two means of nesting, at least in the possessive case. 'The mother of invention' and "invention's mother". Here is a predicate example too: 'The cat is on the mat' and 'On the mat is the cat', although the late is mostly unattested-to these days. -- http://mail.python.org/mailman/listinfo/python-list