I may have misunderstood something.
The original post in this subject sounded to ME likethey had nested
dictionaries and wanted to be ableto ask a method in the first dictionary
totake an unspecified number of arguments thatwould be successive keys and
return the results.
I mean if A was a dicti
On Sun, Apr 3, 2022 at 2:46 PM Cecil Westerhof via Python-list <
python-list@python.org> wrote:
> Betty Hollinshead writes:
>
> > "Memoising" is the answer -- see "Python Algorithms" by Magnus Lie
> Hetland.
> > In the mean time, here a simplified version of "memoising" using a dict.
> > This ver
Marco Sulla wrote at 2022-4-3 21:17 +0200:
>On Sun, 3 Apr 2022 at 18:57, Dieter Maurer wrote:
>> You know you can easily implement this yourself -- in your own
>> `dict` subclass.
>
>Well, of course, but the question is if such a method is worth to be
>builtin, in a world imbued with JSON. I suppo
On Mon, 4 Apr 2022 at 05:19, Marco Sulla wrote:
>
> On Sun, 3 Apr 2022 at 18:57, Dieter Maurer wrote:
> > You know you can easily implement this yourself -- in your own
> > `dict` subclass.
>
> Well, of course, but the question is if such a method is worth to be
> builtin, in a world imbued with
Betty Hollinshead writes:
> "Memoising" is the answer -- see "Python Algorithms" by Magnus Lie Hetland.
> In the mean time, here a simplified version of "memoising" using a dict.
> This version handles pretty large fibonacci numbers!
>
> # fibonacci sequence
> # memoised - but using a simple dict
On Sun, 3 Apr 2022 at 21:46, Peter J. Holzer 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?
> I'm not sure whet
"Memoising" is the answer -- see "Python Algorithms" by Magnus Lie Hetland.
In the mean time, here a simplified version of "memoising" using a dict.
This version handles pretty large fibonacci numbers!
# fibonacci sequence
# memoised - but using a simple dictionary (see Python Algorithms, p177)
m
On 2022-04-03 17:58:09 +0300, Kirill Ratkin via Python-list wrote:
> 02.04.2022 23:44, Marco Sulla пишет:
> > A proposal. Very often dict are used as a deeply nested carrier of
> > data, usually decoded from JSON. Sometimes I needed to get some of
> > this data, something like this:
> >
> > data["
On Sun, 3 Apr 2022 at 18:57, Dieter Maurer wrote:
> You know you can easily implement this yourself -- in your own
> `dict` subclass.
Well, of course, but the question is if such a method is worth to be
builtin, in a world imbued with JSON. I suppose your answer is no.
--
https://mail.python.org
On Sun, 3 Apr 2022 at 16:59, Kirill Ratkin via Python-list
wrote:
>
> Hi Marco.
>
> Recently I met same issue. A service I intergated with was documented
> badly and sent ... unpredictable jsons.
>
> And pattern matching helped me in first solution. (later I switched to
> Pydantic models)
>
> For
Marco Sulla wrote at 2022-4-2 22:44 +0200:
>A proposal. Very often dict are used as a deeply nested carrier of
>data, usually decoded from JSON. Sometimes I needed to get some of
>this data, something like this:
>
>data["users"][0]["address"]["street"]
>
>What about something like this instead?
>
>
On 2022-04-03 at 18:01:58 +0300,
Kirill Ratkin via Python-list wrote:
> It seems 'case if' should help with types:
>
> case {"users": [{"address": {"street": street}}]} if isinstance(street,
> str):
reduce(lambda x, y: x[y], ["users", 0, "address", "street"], data)
Unless it's y[x] rather than
On Mon, 4 Apr 2022 at 00:59, Kirill Ratkin via Python-list
wrote:
>
> Hi Marco.
>
> Recently I met same issue. A service I intergated with was documented
> badly and sent ... unpredictable jsons.
>
> And pattern matching helped me in first solution. (later I switched to
> Pydantic models)
>
> For
To my previous post.
It seems 'case if' should help with types:
case {"users": [{"address": {"street": street}}]} if isinstance(street,
str):
:)
// BR
02.04.2022 23:44, Marco Sulla пишет:
A proposal. Very often dict are used as a deeply nested carrier of
data, usually decoded from JSON.
Hi Marco.
Recently I met same issue. A service I intergated with was documented
badly and sent ... unpredictable jsons.
And pattern matching helped me in first solution. (later I switched to
Pydantic models)
For your example I'd make match rule for key path you need. For example:
data = {
15 matches
Mail list logo