When using a list comprehension, the list created under the hood can be referred to with locals()['_[1]']. In the case of nested elements, the elements are named _[2], _[3], etc, as you delve deeper into the nested items. The 'anonymous' list exists only while the list comprehension executes,ie. only during the work between '[' and ']'. It's sometimes handy to be able to refer to this list for in-line processing during the list comprehension. Here's an easy example. Let's say I wanted to join three lists together, removing any duplicate elements:
>>> L1 = [ 1,2,3 ] >>> L2 = [ 2,3,4 ] >>> L3 = [ 2,4,5 ] >>> [ x for x in L1 + L2 + L3 if x not in locals()['_[1]'] ] [1, 2, 3, 4, 5]
Now, the 'gotcha' is that locals()['_[n]'] is not just incremented for each nested list comprehension, it's incremented whenever a list comprehension is used in the local scope. So, if you've executed four list comprehensions previously in the run of the local scope, your next one is referenced as locals()['_[5]']. This is most evident within a loop:
>>> for x in [1,2,3]: ... [ x for x in l1 + l2 + l3 if x not in locals()['_[1]'] ] #this will work ... [ x for x in l1 + l2 + l3 if x not in locals()['_[1]'] ] #this key no longer exists ... [1, 2, 3, 4, 5] Traceback (most recent call last): File "", line 3, in KeyError: '_[1]'
>>> for x in [1,2]: ... [ x for x in l1 + l2 + l3 if x not in locals()['_[1]'] ] ... [ x for x in l1 + l2 + l3 if x not in locals()['_[2]'] ] #here's the increment ... [1, 2, 3, 4, 5] [1, 2, 3, 4, 5] [1, 2, 3, 4, 5] [1, 2, 3, 4, 5]
Every once in a while, I get a wild hair to change up my desktop. Every time I've played with an xterm replacement that supports transparency, I generally get annoyed within hours, being too lazy to actually spend any time tweaking it. For whatever reason, today I bit the bullet, and took a couple of minutes set up aterm to be useable. There was actually no excuse for my earlier laziness - all my 'problems' were settled with just a few entries to ~/.Xdefaults:
These take care of the annoyances (such as the character mapping for my backspace key changing within a vi session). Then, enabling transparency in empty frames for ion3 brings back the old school behavior (well ion2 old school =]):