26 Oct
2021
26 Oct
'21
2:21 a.m.
On Tue, Oct 26, 2021 at 1:10 PM David Mertz, Ph.D. <david.mertz@gmail.com> wrote:
I like this. I think explicitly discussing order of inclusion would be worthwhile. I know it's implied by the approximate equivalents, but actually stating it would improve the PEP, IMO.
For example:
nums = [(1, 2, 3), (1.0, 2.0, 3.0)] nset = {*n for n in nums}
Does 'nset' wind up containing integers or floats? Is this a language guarantee?
Easy way to find out: take out the extra nesting level and try it.
nums = [1, 2, 3, 1.0, 2.0, 3.0] nset = {n for n in nums} nset {1, 2, 3}
The *n version would have the exact same behaviour, since it will see the elements in the exact same order. ChrisA