You can get almost the same result using pattern matching. For example, your
"foo:bar;baz".partition(":", ";")
can be done by a well-known matching idiom:
re.match(r'([^:]*):([^;]*);(.*)', 'foo:bar;baz').groups()
___
Python-ideas mailing list -- python-id
Steven D'Aprano wrote:
> > That seems to be close to the opinion of Robert C Martin:
> http://blog.cleancoder.com/uncle-bob/2016/05/01/TypeWars.html
> He also has some comments on languages like Koitlin and Swift that have
> gone down that path of mandatory static typing:
> http://blog.cleancoder
Neil Girdhar wrote:
> I wish this had gotten more attention! :)
I wonder what the various projects are doing to handle the latest version of
Python, if they need a parse tree with whitespace information. (The projects I
know of are yapf, black, mypy, pytype, kythe -- are there others?)
ast.pars
MRAB wrote:
> From a mathematical point of view, x-y is equivalent to x+(-y).
>From a mathematical point of view, x+y is equivalent to y+x, but I suppose
>that ship has sailed a long long time ago. ("++", "--", etc. would have been
>better choices for operators)[*]
Anyway, if you're going to a
David Mertz wrote:
> The pattern of "Create an empty collection, then add stuff in a loop" is
> quite common, ...
Or you can use comprehensions, in which case there's no need for creating an
empty collection.
s = {f(x) for x in some_list}
vs
s = set()
for x in some_list:
s.add(f(x))
__
Chris Angelico wrote:
> On Sat, Mar 13, 2021 at 1:46 PM Peter Ludemann peter.ludem...@gmail.com wrote:
> > It's not clear to me what surprising behaviors there would be. Javascript
> > seems to do OK with optional semicolons - presumably its algorithm is
> > simi
On Fri, 12 Mar 2021 at 18:27, Guido van Rossum wrote:
> On Fri, Mar 12, 2021 at 6:23 PM Peter Ludemann
> wrote:
>
>> [I wonder why C didn't adopt BCPL's convention for eliding semi-colons?
>> ...]
>>
>
> [Presumably because it caused too many surp
Guido van Rossum wrote:
> Can we skip ahead to considering how to implement this? I can think of two
> approaches: either hack the lexer to special-case a newline followed by a
> period (which currently can never start a line), or redesign the syntax to
> allow NEWLINE INDENT ‘.’ . NEWLINE
Ben Avrahami wrote 9 Feb 2021, 03:30:
> That's the current alternative, but namedtuples (unlike dataclasses) are
> slotted, which makes them more space-efficient and (slightly) faster.
When I use @dataclass(frozen=True), I manually add a __slots__ attribute. I
presume this makes the resulting
I use dataclass (with frozen=True) instead of NamedTuple - and I can do
mixins.
https://docs.python.org/3/library/dataclasses.html
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https
A variant of the problem is the "occurs check", used in theorem proving:
https://en.wikipedia.org/wiki/Occurs_check
Removing the occurs check reduces the cost of unifying two terms (t1, t2)
from *O(size(t1) + size(t2))* to *O(min(size(t1), size(t2)))*, which is why
Prolog implementations don't do t
With lib2to3 going away (https://bugs.python.org/issue40360), it seems to
me that some of its functionality for handling "whitespace" can be fairly
easily added to the ast module. (By "whitespace", I mean things like
indent, dedent, comments, backslash; and also the ability to manipulate the
encode
12 matches
Mail list logo