PEP Idea: Multi-get for lists/tuples and dictionaries (inspired in NumPy)

Dan Stromberg drsalists at gmail.com
Thu Mar 19 11:05:18 EDT 2020


On Thu, Mar 19, 2020 at 7:47 AM Peter J. Holzer <hjp-python at hjp.at> wrote:

> On 2020-03-19 14:24:35 +0000, Rhodri James wrote:
> > On 19/03/2020 13:00, Peter J. Holzer wrote:
> > > It's more compact, especially, if "d" isn't a one-character variable,
> > > but an expression:
> > >
> > >      fname, lname =
> db[people].employee.object.get(pk=1234)[['first_name', 'last_name']]
> > >
> > > vs.
> > >
> > >      fname = db[people].employee.object.get(pk=1234)['first_name']
> > >      lname = db[people].employee.object.get(pk=1234)['last_name']
> >
> > I have to say I don't think that's more compact at all.  It's too wide
> > to be compact.
>
> But 83 characters is still more compact than 121 characters.
>

It's smaller (in a way), but is it more clear?  Compare to regular
expressions: they're small, but they tend to be a mess.

Remember that the complexity of a programming a language varies with the
square of its number of features.  Complex languages are not good
languages.  A good language has a small core and extensibility via
libraries.


More information about the Python-list mailing list