3 ms·
Looking at it a bit more, it's sort-of-obvious that that's what it is, if you've seen the Sieve before. However: > i for a[::i] in <whatever> Mind blown. How
by StavrosK 16y ago
Looking at it a bit more, it's sort-of-obvious that that's what it is, if you've seen the Sieve before. However:
> i for a[::i] in <whatever>
Mind blown. How does assigning to an array even work? I'm guessing this is way-undefined-speak for setting elements, and I am simultaneously dazzled by its brilliance and horrified by its stupidity.
- cool-RR 16y agoYes, that was the desired effect :)
- zem 16y agoyeah, i figured out what it did by playing in the repl, but i still can't find it documented anywhere.
- StavrosK 16y agoI tried a bit in the REPL and couldn't replicate it completely, but I didn't try hard. It seems to only work because of the CPython internals, so it seems to be implementation-specific and undocumented.
- cool-RR 16y agoNot true, it's part of Python's syntax. Here it is in Pypy: Python 2.5.2 (79560, Nov 26 2010, 14:57:55) [PyPy 1.4.0] on win32 >>> a = [1, 2 ,3] >>> for a[:] in [[6, 7, 8]]: ... pass >>> print(a) [6, 7, 8]
- StavrosK 16y agoSo what does it do? Run the expression first and assign to whatever's there? It seems that it would only work to assign to a slice, as anything else would be overwritten, but why?