I've got some Python source code blocks in my Org mode document and when I print lists as output I get an org table of one row with all elements (regardless of whether I create a session or not):

#+BEGIN_SRC python :session
list = [1, 2, 3, 4]

| 1 | 2 | 3 | 4 |

For long lists this is inconvenient (also when exporting to LaTeX/PDF, for example). Is there a way to change the output to one column, multiple rows?

I have tried adding :results list to the source block header, which sort of gives me what I want. Nevertheless, a table is preferred over a list.


You can output a column vector by mapping each list element to a row element of a new list of lists (matrix):

#+BEGIN_SRC python :session
mylist = [1, 2, 3, 4, 5, 6]
map( lambda x: [x], mylist )

| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
  • Interestingly, when trying your solution in Python3 it didn't work (the output was <map object at 0x7fe3b0a36160>). So I decided to convert your solution to a list comprehension: [ [x] for x in mylist ]. This works also in Python3 – ph0t0nix Nov 11 '16 at 17:13

Your Answer

