dict.get_deep()

Peter J. Holzer hjp-python at hjp.at
Fri Apr 8 02:27:04 EDT 2022


On 2022-04-03 23:17:04 +0200, Marco Sulla wrote:
> On Sun, 3 Apr 2022 at 21:46, Peter J. Holzer <hjp-python at hjp.at> wrote:
> > > > data.get_deep("users", 0, "address", "street", default="second star")
> >
> > Yep. Did that, too. Plus pass the final result through a function before
> > returning it.
> 
> I didn't understand. Have you added a func parameter?

Yes. Look at the code I posted (it's only 9 lines long).

> > I'm not sure whether I considered this when I wrote it, but a function
> > has the advantage of working with every class which can be indexed. A
> > method must be implemented on any class (so at least dict and list to be
> > useful).
> 
> You're right, but where to put it? I don't know if an iterableutil package
> exists. If included in the stdlib, I don't know where to put it. In
> collections maybe?

Yes, that seems like the least bad choice.

        hp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp at hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://mail.python.org/pipermail/python-list/attachments/20220408/0604c9a8/attachment.sig>


More information about the Python-list mailing list