On Fri, Dec 13, 2019, at 19:24, Steven D'Aprano wrote:
> `__builtins__` is a private CPython implementation detail, so the above
> is always wrong in user code. Better:
Wait, it is?
Is there then no portable way to do the things like:
- providing an alternate __builtins__ to evaluated code, with
I think it's necessary to add a segment() method to str type or string module.
This method is used to split a string into m parts and return all cases. With
segment(), you can avoid tedious calculation and indexing if you want to
segment a string.
For example:
segment('1234', m=3) -> [('1', '2
What are the practical uses for this? I don't recall having done this in my
soon 20 years career.
> On 14 Dec 2019, at 15:42, smfiles <1668151...@qq.com> wrote:
>
> I think it's necessary to add a segment() method to str type or string
> module. This method is used to split a string into m p
On 12/14/19 4:06 AM, smfiles wrote:
> I think it's necessary to add a segment() method to str type or string
> module. This method is used to split a string into m parts and return all
> cases. With segment(), you can avoid tedious calculation and indexing if you
> want to segment a string.
>
>
This feels much too special purpose for a string method, and probably for
anything in the standard library. I'm not sure when someone would want this.
But it's an only very sightly special case of integer composition (
https://en.wikipedia.org/wiki/Composition_(combinatorics)). And related to
that
Here's a discussion of both a conceptually simple and a convoluted but fast
version (the latter, naturally, by Tim Peters). This is for integer
partitions, but compositions are simply the permutations on the full length
of the list of each partition.
http://code.activestate.com/recipes/218332-gene
Tim Peters writes:
> But hasn't it already been settled by experience? There is nothing
> unique about `first(set)` implicitly appealing to iteration order.
I'm not sure. I wouldn't think to use "first" on a set in my own code
(and in others' code I'd consider it a code smell in many contexts
smfiles writes:
> I think it's necessary to add a segment() method to str type or
> string module. This method is used to split a string into m parts
> and return all cases. With segment(), you can avoid tedious
> calculation and indexing if you want to segment a string.
In addition to David
On Sat, Dec 14, 2019 at 3:56 PM David Mertz wrote:
> [...] compositions are simply the permutations on the full length of the
> list of each partition.
>
Using permutations of partitions would be overkill. For compositions of a
given fixed length, it's much easier to compute them directly using
Apologies for the bad formatting. Here are the relevant bits, better formatted
(I hope):
>>> segment = lambda s, m: (tuple(s[i:j] for i, j in zip((0,)+c,
c+(len(s),)))
... for c in itertools.combinations(range(1, len(s)), m-1))
>>>
>>> list(segment("12345", m=3))
[('1',
[David Mertz ]
> Here's a discussion of both a conceptually simple and a convoluted but
> fast version (the latter, naturally, by Tim Peters).
Not really convoluted - it's the natural thing you'd do "by hand" to
move from one partition to the next: look at the current partition,
throw out the 1s,
I had not known about math.comb() and math.perm() being added in 3.8. Those
kinda feel to me like "not every one line function needs to be in the
standard library." But I guess wiser people than me saw a reason they are
needed.
On Sat, Dec 14, 2019, 3:00 PM Tim Peters wrote:
> Not really convolu
On Sat, Dec 14, 2019 at 2:50 AM Stephen J. Turnbull <
turnbull.stephen...@u.tsukuba.ac.jp> wrote:
> Did you intend to reply only to me?
Nope - I hate list that don’t default to replying to the list (I know
that’s an unpopular opinion).
I was wondering why no one comment on it.
> I’m quite con
> > I think we all agree that it does not belong in
> > __builtins__,
>
> Do we? I'm not convinced. We already have all() and any()
> in builtins, which are similar in that they operate on
> iterators or iterables.
Good point — I was assuming with all the hostility (OK, skepticism) to the
idea, t
On Sat, Dec 14, 2019, at 04:06, smfiles wrote:
> I think it's necessary to add a segment() method to str type or string
> module. This method is used to split a string into m parts and return
> all cases. With segment(), you can avoid tedious calculation and
> indexing if you want to segment a
> The argument that first(it) and next(it) "look the same" doesn't convince
> me; if these look the same then all function applications look the same,
> and that can certainly not have been Meertens' intention. But if everyone
> thinks that first() should raise, fine, this thread is way too long al
Hello!
I think it will be useful in Python syntax if we can use "elif" in "for" and
"while" statements besides "else"
Example
for i in range(j):
...
elif i > 5:
...
else:
...
What you think about this change?
___
Python-ideas mailing list -
On Sun, Dec 15, 2019 at 10:16 AM wrote:
>
> Hello!
> I think it will be useful in Python syntax if we can use "elif" in "for" and
> "while" statements besides "else"
>
> Example
> for i in range(j):
> ...
> elif i > 5:
> ...
> else:
> ...
>
> What you think about this change?
Can you
On 12/14/19 4:37 PM, komissar.off.and...@gmail.com wrote:
Hello!
I think it will be useful in Python syntax if we can use "elif" in "for" and "while"
statements besides "else"
Example
for i in range(j):
...
elif i > 5:
...
else:
...
What you think about this change?
Can you sa
On Dec 14, 2019, at 12:36, Christopher Barker wrote:
>
> Of the top of my head, I can’t think of a single non-contrived example of
> using a bare iterator in case that is not specifically doing something
> “special”.
Calling iter on a container is hardly the only way to get an Iterator. You al
A pattern I've written a number of times is roughly:
lines = open(fname)
header = next(lines)
for line in lines:
process (line, header)
That's not so artificial, I think. Of course, first() would also work here.
But I'm not sure it's any particular advantage in this case.
On Sun, Dec 15, 201
On Sat, Dec 14, 2019 at 9:46 PM Andrew Barnert wrote:
> > Of the top of my head, I can’t think of a single non-contrived example
> of using a bare iterator in case that is not specifically doing something
> “special”.
>
> Calling iter on a container is hardly the only way to get an Iterator. You
22 matches
Mail list logo