On 2026-06-13, Paul Rubin <[email protected]> wrote:
> Jon Ribbens <[email protected]> writes:
>> Lawrence's version used your neat dict(line.split()[:2] ...) trick.
>
> Maybe this:
>
>    dict((a,int(b)) for a,b in (x.split()[:2] for x in xs))
>
> I feel like there should be a way to do this with the := operator
> instead of the nested generators, but it doesn't seem to be there.

That was the way my version did it? If I use abbreviated variable names
like your version, it's actually shorter than yours ;-)

     {e[0][:-1]: int(e[1]) for x in xs if (e := x.split())}
-- 
https://mail.python.org/mailman3//lists/python-list.python.org

Reply via email to