Steven D'Aprano wrote:
On Thu, Jun 28, 2018 at 10:01:00AM -0700, Chris Barker via Python-ideas wrote:
In [*46*]: {a:[t[0] *for* t *in* b] *for* a,b *in*
groupby(sorted(student_school_list,
key=*lambda* t: t[1]), key=*lambda* t: t[
...
> the rest ought to be legal Python but
But don't all the users who care about citing modules already use the
scientific python packages, with scipy itself at it's center? Wouldn't those
engaging in science or in academia be better stewards of this than systems
programmers? Since you're not asking for anything that can't be done in
For me, it's about setting a standard that is endorsed by the
language, and setting expectations for users. There currently is no
standard, which is why packages use __citation__, __cite__,
__bibtex__, etc., and as a user I don't immediately know where to look
for citation information (without
Mike Selik asked for my opinion on a draft PEP along these lines. I
proposed a slight modification to his idea that is now reflected in his
latest edits. With some details fleshed out, I think this is a promising
idea. I like the a collections class better, of course, but a dict
classmethod is
Why not scipy.cite() or scipy.citation()? I don't see any reason for these
functions to ship with standard python at all.
> -Original Message-
> From: Python-ideas list=sdamon@python.org> On Behalf Of Steven D'Aprano
> Sent: Thursday, June 28, 2018 8:17 PM
> To:
On Thu, Jun 28, 2018, 6:46 PM Nicolas Rolin wrote:
> The questions I should have asked In my original post was :
> - Is splitting lists into sublists (by grouping elements) a high level
> enough construction to be worthy of a nice integration in the comprehension
> syntax ?
>
My intuition is
On Thu, Jun 28, 2018 at 2:25 PM, Andrei Kucharavy
wrote:
>> This is indeed a serious problem. I suspect python-ideas isn't the
>> best venue for addressing it though – there's nothing here that needs
>> changes to the Python interpreter itself (I think), and the people who
>> understand this
2018-06-28 22:34 GMT+02:00 David Mertz :
> I agree with these recommendations. There are excellent 3rd party tools
> that do what you want. This is way too much to try to shoehorn into a
> comprehension.
>
There are actually no 3rd party tools that can "do what I want", because if
I wanted to
Ctrl-Shift-V pastes without HTML formatting.
On Thursday, June 28, 2018, Steven D'Aprano wrote:
> Can I make a plea for people to not post code with source highlighting
> as HTML please? It is rendered like this for some of us:
>
> On Thu, Jun 28, 2018 at 10:01:00AM -0700, Chris Barker via
There are a few tools that can accomplish these map-reduce/transformation
tasks.
See Options A, B, C below.
# Given
>>> import itertools as it
>>> import collections as ct
>>> import more_itertools as mit
>>> student_school_list = [
... ("Albert", "Prospectus"), ("Max",
On Thu, Jun 28, 2018 at 06:57:45AM +0300, Serhiy Storchaka wrote:
> Making a nested class a member you
> don't lost anything, because you always can make it not-nested if you
> don't want it be a member.
You lose the ability to have
Colors.RED.NestedClass() # returns something useful
On Thu, Jun 28, 2018 at 05:25:00PM -0400, Andrei Kucharavy wrote:
> As for the list, reserving a __citation__/__cite__ for packages at the same
> level as __version__ is now reserved and adding a citation()/cite()
> function to the standard library seemed large enough modifications to
> warrant
> On Jun 28, 2018, at 5:30 PM, Chris Barker - NOAA Federal
> wrote:
>
> So maybe a solution is an accumulator special case of defaultdict — it uses a
> list be default and appends by default.
>
> Almost like counter...
Which, of course, is pretty much what your proposal is.
Which makes me
> I think you accidentally swapped variables there:
> student_school_list
> vs student_by_school
Oops, yeah. That’s what I get for whipping out a message before catching a bus.
(And on a phone now)
But maybe you could wrap the defaultdict constructor around a
generator expression that
I think you cheated a little in your cut-and-paste. `student_by_school` is
not defined in the code you've shown. What you **did** define, `
student_school_list` doesn't give you what you want if you use `
defaultdict(list,student_school_list)`.
I thought for a moment I might just use:
[(b,a)
On Thu, Jun 28, 2018 at 5:12 PM Chris Barker via Python-ideas <
python-ideas@python.org> wrote:
> In [97]: student_school_list
> Out[97]:
> [('Fred', 'SchoolA'),
> ('Bob', 'SchoolB'),
> ('Mary', 'SchoolA'),
> ('Jane', 'SchoolB'),
> ('Nancy', 'SchoolC')]
>
> In [98]: result = defaultdict(list,
Hold the phone!
On Thu, Jun 28, 2018 at 8:25 AM, Nicolas Rolin
wrote:
> student_by_school = defaultdict(list)
> for student, school in student_school_list:
> student_by_school[school].append(student)
>
> What I would expect would be a syntax with comprehension allowing me to
>
On Thu, Jun 28, 2018 at 4:59 PM, Steven D'Aprano
wrote:
> Can I make a plea for people to not post code with source highlighting
> as HTML please? It is rendered like this for some of us:
>
> On Thu, Jun 28, 2018 at 10:01:00AM -0700, Chris Barker via Python-ideas
> wrote:
>
> In [*46*]:
On Thu, Jun 28, 2018 at 11:23:49AM -0700, Michael Selik wrote:
> The fact that you didn't use ``setdefault`` here, opting for repeatedly
> constructing new lists via concatenation, demonstrates the need for a
> built-in or standard library tool that is easier to use.
That would be setdefault :-)
Can I make a plea for people to not post code with source highlighting
as HTML please? It is rendered like this for some of us:
On Thu, Jun 28, 2018 at 10:01:00AM -0700, Chris Barker via Python-ideas wrote:
In [*46*]: {a:[t[0] *for* t *in* b] *for* a,b *in*
On Thu, Jun 28, 2018 at 4:34 PM Chris Barker via Python-ideas <
python-ideas@python.org> wrote:
> On Thu, Jun 28, 2018 at 4:23 PM, Greg Ewing
> wrote:
>
>> Nicolas Rolin wrote:
>>
>>> student_by_school = {group_by(school): student for school, student
>>> in student_school_list}
>>>
>>
>> In
On Thu, Jun 28, 2018 at 4:23 PM, Greg Ewing
wrote:
> Nicolas Rolin wrote:
>
>> student_by_school = {group_by(school): student for school, student in
>> student_school_list}
>>
>
> In the spirit of making the target expression look like
> a template for the generated elements,
>
>{school:
Nicolas Rolin wrote:
student_by_school = {group_by(school): student for school, student
in student_school_list}
In the spirit of making the target expression look like
a template for the generated elements,
{school: [student...] for school, student in student_school_list}
--
Greg
On Thu, Jun 28, 2018 at 1:34 PM, David Mertz wrote:
> I'd add one more option. You want something that behaves like SQL. Right
> in the standard library is sqlite3, and you can create an in-memory DB to
> hope the data you expect to group.
>
There are also packages designed to make DB-style
On Thu, Jun 28, 2018 at 3:17 PM, Chris Barker wrote:
> There are also packages designed to make DB-style queries easier.
>
> Here's one I found with a quick google.
>
opps -- hit send too soon:
http://178.62.194.22/
https://github.com/pythonql/pythonql
-CHB
--
Christopher Barker, Ph.D.
One more thing. There's precedent for this: when you start an interactive
Python interpreter it tells you how to get help, but also how to get
copyright, credits and license information:
$ python3
Python 3.6.6 (v3.6.6:4cf1f54eb7, Jun 26 2018, 19:50:54)
[GCC 4.2.1 Compatible Apple LLVM 6.0
That's a lot of responses, thanks for the interest and the suggestions!
Are there other languages or software communities that do something like
> this? It would be nice not to have to invent this wheel. Eventually a PEP
> and an implementation should be presented, but first the idea needs to be
> Are there other languages or software communities that do something like
this? It would be nice not to have to invent this wheel.
While I do not use R regularly, I understand their community is largely
academic-driven, and citations are strongly encouraged as seen in their
documentation:
I agree with these recommendations. There are excellent 3rd party tools
that do what you want. This is way too much to try to shoehorn into a
comprehension.
I'd add one more option. You want something that behaves like SQL. Right in
the standard library is sqlite3, and you can create an in-memory
PyToolz, Pandas, Dask .groupby()
toolz.itertoolz.groupby does this succinctly without any
new/magical/surprising syntax.
https://toolz.readthedocs.io/en/latest/api.html#toolz.itertoolz.groupby
>From https://github.com/pytoolz/toolz/blob/master/toolz/itertoolz.py :
"""
def groupby(key, seq):
On 28/06/18 16:25, Nicolas Rolin wrote:
Hi,
I use list and dict comprehension a lot, and a problem I often have is to
do the equivalent of a group_by operation (to use sql terminology).
For example if I have a list of tuples (student, school) and I want to have
the list of students by school
On Wed, Jun 27, 2018, at 15:04, Elazar wrote:
> People working with sum types might expect the instances of the nested
> class to be instances of the enclosing class. So if the nested class is a
> namedtuple, you get a sum type. The only problem is that there's no way to
> express this subtype
I've been getting those, too, but from the wxPython-dev group. I concur
that they look like googlegroups bounces (although I can't confirm that as
I've been deleting them without much inspection).
On Thu, Jun 28, 2018 at 9:35 AM Chris Barker via Python-ideas <
python-ideas@python.org> wrote:
>
Why not write a helper function? Something like
def group_by(iterable, groupfunc, itemfunc=lambda x:x, sortfunc=lambda
x:x): # Python 2 & 3 compatible!
D = {}
for x in iterable:
group = groupfunc(x)
D[group] = D.get(group, []) + [itemfunc(x)]
if sortfunc is not
On Thu, Jun 28, 2018 at 8:25 AM, Nicolas Rolin
wrote:
>
> I use list and dict comprehension a lot, and a problem I often have is to
> do the equivalent of a group_by operation (to use sql terminology).
>
I don't know from SQL, so "group by" doesn't mean anything to me, but this:
> For example
Hey all,
I've been replying to messages lately, and getting a bounce back:
"""
Hello chris.bar...@noaa.gov,
We're writing to let you know that the group you tried to contact
(python-ideas) may not exist, or you may not have permission to post
messages to the group. A few more details on why you
I think this is a fine idea, but could be achieved by convention, like
__version__, rather than by fiat.
And it’s certainly not a language feature.
So Nathaniel’s right — the thing to do now is work out the convention,
and then advocate for it.
-CHB
On Thu, Jun 28, 2018 at 8:25 AM Nicolas Rolin
wrote:
> I use list and dict comprehension a lot, and a problem I often have is to
> do the equivalent of a group_by operation (to use sql terminology).
>
> For example if I have a list of tuples (student, school) and I want to
> have the list of
Hi,
I use list and dict comprehension a lot, and a problem I often have is to
do the equivalent of a group_by operation (to use sql terminology).
For example if I have a list of tuples (student, school) and I want to have
the list of students by school the only option I'm left with is to write
On 28/06/2018 00:00, Nathan Goldbaum wrote:
> This is an interesting proposal. Speaking as a developer of scientific
> software packages it would be really cool to have support for something
> like this in the language itself.
>
> The software sustainability institute in the UK have written
On Wed, Jun 27, 2018 at 05:20:01PM -0400, Andrei Kucharavy wrote:
[...]
> To remediate to that situation, I suggest a __citation__ method associated
> to each package installation and import. Called from the __main__,
> __citation__() would scan __citation__ of all imported packages and return
>
On Wed, 27 Jun 2018 17:19:35 -0700
Nathaniel Smith wrote:
> On Wed, Jun 27, 2018 at 2:20 PM, Andrei Kucharavy
> wrote:
> > To remediate to that situation, I suggest a __citation__ method associated
> > to each package installation and import. Called from the __main__,
> > __citation__() would
Mostly historical reasons I guess, we started with static types because
most class extension examples were using it, and it worked for all we did
at the time (including the __class__ assign trick). We then got hit by the
change, and solved the issue by patching python.
Now keeping our own patched
> Greg
> Or perhaps this could be made to work somehow:
>
> class Color(Enum(int)):
> RED = 1
> GREEN = 2
> BLUE = 3
> i_get_left_alone = 4.2
Enum already is callable - it creates Enum subclasses.
e.g.
Color = Enum("Color", ("RED", "GREEN", "BLUE"))
(or
Have you tried just instantiating a Counter() instead ? All missing
keys are considerd to be 0 in a fresh counter. So for example:
>>> c = Counter()
>>> c["a"] += 1
>>> c
Counter({'a': 1})
>>> c["b"]
0
works exactly this way. Which means there's no difference between what
you're suggesting
45 matches
Mail list logo