[Python-ideas] Re: "return if "

2020-06-19 Thread Robert DeLanghe
You can already do compact conditional returns with the current syntax: def foo(a, b): return (a != b or None) and a * b or even: foo = (lambda a, b: (a != b or None) and a * b) both return: foo(2, 5) # 10 foo(1, 1) # None ... but clarity would be better. On Fri, Jun 19, 2020 at 4:

[Python-ideas] Re: Extend the range functionality to allow infinite ranges

2020-06-19 Thread Robert DeLanghe
This is not really the best syntax, but I thought this generator expression might be of interest: counter = (d.update(n=d['n']+1) or d['n'] for d in [dict(n=-1)] for _ in iter(int,1)) It counts forever starting at 0. I was playing with only using generator syntax... On Fri, Jun 19, 2020 at 1:32

[Python-ideas] Re: New syntax for dict literals

2020-06-11 Thread Robert DeLanghe
I like Atsou's suggestion of omitting the key for literals: d = {:name, :addr, ’tel': '123-4567’} but using empty kwargs feels gross: d = dict(=name, =addr, tel='123-456') And this feels like it could easily lead to confusion: d = dict(name, addr, tell='123-456') On Thu, Jun 11, 2020 at 4:05