How about allowing to create multiple items for each loop in comprehension?
I'm not sure this grammar is available, though.
for example:
[loop for set]
s = set()
for i in range(10):
s.add(i)
s.add(i * 10)
[current comprehension]
s = {
x
for i in range(10)
for x in (i, i * 10)
}
[suggested comprehension]
s = {
i, i * 10
for i in range(10)
}
[loop for dict]
dic = {}
for i in range(10):
dic[i] = i * 10
dic[i * 10] = i
[current comprehension]
dic = {
k: v
for i in range(10)
for k, v in ((i, i * 10), (i * 10, i))
}
[suggested comprehension]
dic = {
i: i * 10,
i * 10: i
for i in range(10)
}
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/E3P5CP5BMYRG3JUCD2Y5QVBJ6K2Q3PJT/
Code of Conduct: http://python.org/psf/codeofconduct/