Crosscompute-select


Pay Notebook Creator: Salah Ahmed0
Set Session Lifetime: 10 minutes0
Total0

Using the Select Plugin

This notebook-tool demonstrates using the select plugin in your code

The select plugin takes strings separated by new lines and gives the user the option to choose from among them, able to make multiple selections.

To choose default selections for the user you have to formulate your strings list as follows

  1. name your variable with a suffix of "select" or "options"
  2. list default selections first
  3. insert an empty line
  4. list the whole complete list.

{mode_select: mode ? mode of transportation}

In [19]:
# Crosscompute
mode_select = """
    walk
    bike
    
    bike
    walk
    run
    jazz hands
    """
In [20]:
import itertools
modes = [x.strip() for x in itertools.takewhile(lambda x: x.strip() != '', mode_select.strip().splitlines())]
In [21]:
if len(modes) == 0:
    print("I don't like to move")
elif len(modes) == 2:
    print('I love to %s' % (' and '.join(modes)))
else:
    string = ', '.join(modes[:-1]) + ', and %s' % modes[-1]
    print('I love to %s' % string)
I love to walk and bike