On Mon, Oct 7, 2019, at 09:22, Rhodri James wrote: > On 04/10/2019 20:34, Caleb Donovick wrote: > > The first and perhaps the most obvious, is doing relational queries. > > ``` > > where_x_1 = db[x=1] > > ``` > > is more beautiful than > > ``` > > where_x_1 = db[dict(x=1)] > > where_x_1 = db[{'x': 1}] > > # or by abusing slices > > where_x_1 = db['x':1] > > # or in the style of Pandas > > where_x_1 = db[db['x'] == 1] > > ``` > > OK, I'm not sure what you're trying to do here, which all on its own > says that what you're doing isn't self-explanatory. Would I be right in > thinking you want a shorthand for: > > where_x_1 = [k for k,v in db if v == 1] > > If so, I'd rather the comprehension, thanks. It at least says what it does.
It'd be [v for v in db if v['x'] == 1], anyway, but the point is the list comprehension can't be analyzed by frameworks like Pandas (to execute more efficiently) or SqlAlchemy (to turn it into a sql query that gets executed server-side). And for that matter can't return any type other than a list [or generator, if you used the generator expression syntax instead] I'm not convinced either (this is effectively a special syntax that only works for equality, whereas you can't do db[x>=0]), but using comprehension syntax for cases like these would require a much more sweeping change like AST literals (something that, for example, C# has, but which can't possibly work as smoothly as it does there without static typing) _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/O7TZTAWZN5SOKEDTDTIMWQ4KKUDQC2L5/ Code of Conduct: http://python.org/psf/codeofconduct/