Here's a generator that yields the chunks you want:
def chunks(lst, n):
"""Yield successive n-sized chunks from lst."""
for i in range(0, len(lst), n):
yield lst[i:i + n]
import pprint
pprint.pprint(list(chunks(range(10, 75), 10)))
[[10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
[20, 21, 22, 23, 24, 25, 26, 27, 28, 29],
[30, 31, 32, 33, 34, 35, 36, 37, 38, 39],
[40, 41, 42, 43, 44, 45, 46, 47, 48, 49],
[50, 51, 52, 53, 54, 55, 56, 57, 58, 59],
[60, 61, 62, 63, 64, 65, 66, 67, 68, 69],
[70, 71, 72, 73, 74]]
If you're using Python 2, you should use xrange()
instead of range()
:
def chunks(lst, n):
"""Yield successive n-sized chunks from lst."""
for i in xrange(0, len(lst), n):
yield lst[i:i + n]
Also you can simply use list comprehension instead of writing a function, though it's a good idea to encapsulate operations like this in named functions so that your code is easier to understand. Python 3:
[lst[i:i + n] for i in range(0, len(lst), n)]
Python 2 version:
[lst[i:i + n] for i in xrange(0, len(lst), n)]
Best Answer
With the mouse, you can drag the window sizes around.
Click anywhere on the mode line that is not otherwise 'active' (the buffer name is safe, or any unused area to the right hand side), and you can drag up or down.
Side-to-side dragging requires a very precise click on the spot where the two mode lines join.
C-x - (
shrink-window-if-larger-than-buffer
) will shrink a window to fit its content.C-x + (
balance-windows
) will make windows the same heights and widths.C-x ^ (
enlarge-window
) increases the height by 1 line, or the prefix arg value. A negative arg shrinks the window. e.g. C-- C-1 C-6 C-x ^ shrinks by 16 rows, as does C-u - 1 6 C-x ^.(There is no default binding for
shrink-window
.)C-x } (
enlarge-window-horizontally
) does likewise, horizontally.C-x { (
shrink-window-horizontally
) is also bound by default.Following one of these commands with
repeat
(C-x z to initiate, and just z for continued repetition) makes it pretty easy to get to the exact size you want.If you regularly want to do this with a specific value, you could record a keyboard macro to do it, or use something like
(global-set-key (kbd "C-c v") (kbd "C-u - 1 6 C-x ^"))
Or this:
(global-set-key (kbd "C-c v") (kbd "C-x o C-x 2 C-x 0 C-u - 1 C-x o"))
Which is a smidgen hacky, so this would be better:
Tangentially, I also love
winner-mode
which lets you repeatedly 'undo' any changes to window configurations with C-c left (whether the change is the size/number/arrangement of the windows, or just which buffer is displayed). C-c right returns you to the most recent configuration. Set it globally with(winner-mode 1)