[Python-ideas] Respectively and its unpacking sentence

Pavol Lisy pavol.lisy at gmail.com
Fri Jan 29 11:04:36 EST 2016


I would really like

(a;b;c) in L

vs

a in L and b in L and c in L

or

all(i in L for i in (a,b,c))

because readability very matters.

But if I understand then this is not what we could get from your
proposal because a;b;c is not expression. Right?

So we have to write something like

vec=[None]*3
vec=(a;b;c) in L
all(vec) # which is now equivalent to (a in L and b in L and c in L)


> vec=[]*10
> $vec = $u + $v

First row is mistake (somebody wrote it yet) but why not simply? ->

vec = list($u +$v)

Because $u+$v is not expression. It is construct for "unpacking"
operations. It could be useful to have "operator" (calling it operator
is misleading because result is not object) to go back to python
variable. (but with which type? tuple?) Probably $(a;b) could
("return") be transformed to tuple(a,b)

a=[1,2]
print(a)
print($a)
print($$a)
----
[1,2]
1
2
(1,2)

So I could write

a in L and b in L and c in L

as

all($((a;b;c) in L))           # which is much less nice as "(a;b;c) in L"

and

all(i in L for i in (a,b,c))   # which is similar readable and don't
need language changes

> s=0
> s;s;s += a;b;c; * d;e;f
> which result in s being a*d+b,c*e+d*f

do you mean a*d+b*d+c*f ?

-------

Your idea is interesting. If you like to test it then you could
improve implementation of next function and play with it (probably you
will find some caveats):

def respectively(statement):
  if statement!='a;b=b;a':
    raise SyntaxError("only supported statement is 'a;b=b;a'")
  exec('global a\nglobal b\na=b\nb=a')

a,b=1,2
respectively('a;b=b;a')
print(a,b)
2 2

Unfortunately this could work only in global context due to
limitations around 'exec' and 'locals' functions.


More information about the Python-ideas mailing list