Forum Archive

How to shuffle selected lines (random sort) in Editorial ?

tguillemin

I have, e.g., the following lines in the middle of a larger text

Beijing
Berlin
London
Moscow
New York
Paris

How do I shuffle that list (and not the rest of the text) ?

Thanks in advance

ccc

First, you need to know how to find where the list starts and ends. Methods:

  • User selects the text she wants shuffled
  • Text is between --- and --- (some character or group of characters that will be unique)
  • Text will be on lines 5 thru 10, etc.

Second, you have a Python action that does something like:

import random
my_list = my_text.split('\n')
random.shuffle(my_list)
my_text = '\n'.join(my_list)
omz

Here's a very simple workflow that shuffles the selected lines:

http://www.editorial-workflows.com/workflow/5835284772028416/4_zBQGBrkcA

The Python code is obviously very similar to @ccc's.

tguillemin

@ccc

First of all, thank you

But, second, I get an error, which most certainly originates in the fact that I am an ignoramus in Python, and do not know how to adapt your answer to my needs.

Thank you again nevertheless

tguillemin

@omz

Thank you very much for youe answer, which works perfectly.

And thank you too for Editorial, which is a truly beautiful app (NB: on Mac OSX, my editor of choice is Vim, not for programming, but for writing)

Side question (only answer if you have got time) : how to sort that same list on the n-th column ?

And of course, best wishes for 2017