|
@dabeaz | |||||
|
Sure, you could use _ as a throw-away variable in a Python for-loop. Yeah, you could definitely do that... like everyone else. Or you could just do this:
>>> a = [ (0, 'Hello'), (1, 'Satan') ]
>>> for {}[()], x in a:
... print(x)
...
Hello
Satan
>>>
Be different.
|
||||||
|
||||||
|
David Beazley
@dabeaz
|
26. stu |
|
You can also mix things up...
>>> for {}[(),...,()], x in a:
... print(x)
...
Hello
Satan
>>>
|
||
|
|
||
|
David Beazley
@dabeaz
|
27. stu |
|
>>> a = [(0, 'Hello'), (1, 'Satan')]
>>> for (lambda:()).foldl,x in a:
... print(x)
...
Hello
Satan
>>>
|
||
|
|
||
|
David Beazley
@dabeaz
|
27. stu |
|
The key to good code is for it to look impressive.
|
||
|
|
||
|
David Beazley
@dabeaz
|
26. stu |
|
For what it's worth, if you want to write code like this, you should take my compilers course ;-). A huge discussion (and design problem) centers around the concept of lvalue and rvalue expressions in assignment operations. This is a diabolical lvalue.
|
||
|
|
||
|
Baptiste Mispelon
@bmispelon
|
28. stu |
|
I made sg "useful" with it:
ᚐ = type('ᚐ',(object,),{'ᚐ':{},'__getattr__':lambda s,a:s.ᚐ[a],'__setattr__':lambda s,a,v:s.ᚐ.__setitem__(a,s.ᚐ[a]+v)if a in s.ᚐ else s.ᚐ.__setitem__(a,v)})()
for ᚐ.i, ᚐ.s in [(600, 'sa'), (60, 'ta'), (6, 'n')]: pass
print(ᚐ.i, ᚐ.s)
|
||
|
|
||
|
Baptiste Mispelon
@bmispelon
|
28. stu |
|
Non-minified source code at gist.github.com/bmispelon/739f…
|
||
|
|
||
|
Hazelnut
@HazelStones
|
26. stu |
|
What sorcery is this?
|
||
|
|
||
|
David Beazley
@dabeaz
|
26. stu |
|
Python.
|
||
|
|
||
|
Kelly Sovacool
@kelly_sovacool
|
26. stu |
|
Thanks, I hate it. pic.twitter.com/Xuvuqe4I59
|
||
|
|
||
|
David Beazley
@dabeaz
|
26. stu |
|
It looks better from the other side of the monitor.
|
||
|
|
||