That's a list comprehension. It is equivalent to (but more efficient than):
views = []
for v in sublime.active_window().views():
views.append(v)
Note that in this case, they should have just used list
:
views = list(sublime.active_window().views())
There are other types of comprehensions that were introduced in python2.7:
set comprehension:
{x for x in iterable}
and dict comprehension:
{k:v for k,v in iterable_that_yields_2_tuples}
So, this is an inefficient way to create a dictionary where all the values are 1:
{k:1 for k in ("foo","bar","baz")}
Finally, python also supports generator expressions (they're available in python2.6 at least -- I'm not sure when they were introduced):
(x for x in iterable)
This works like a list comprehension, but it returns an iterable object. generators aren't particularly useful until you actually iterate over them. The advantage is that a generator calculates the values on the fly (rather than storing the values in a list which you can then iterate over later). They're more memory efficient, but they execute slower than list-comps in some circumstances -- In others, they outshine list-comprehensions because it's easy to say -- Just give me the first 3 elements please -- whereas with a list comprehension, you'd have to calculate all the elements up front which is sometimes an expensive procedure.