// Numbas version: exam_results_page_options {"name": "Sort a list of lists by a particular key", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"name": "Sort a list of lists by a particular key", "tags": [], "metadata": {"description": "
Obosolete: there's now a built-in function sort_by
.
Defines a custom function sort_by to sort a list of lists by the elements at the given index.
\nYou could do a similar thing to sort lists of dictionaries.
", "licence": "Creative Commons Attribution 4.0 International"}, "statement": "{table(zip(names,order),['Name','Position'])}
\nThe order is {join(sorted,', ')}
", "advice": "", "rulesets": {}, "extensions": [], "variables": {"names": {"name": "names", "group": "Ungrouped variables", "definition": "[\"A\",\"B\",\"C\",\"D\",\"E\",\"F\"]", "description": "The list that we want to sort.
", "templateType": "anything"}, "order": {"name": "order", "group": "Ungrouped variables", "definition": "shuffle(1..len(names))", "description": "The values that will be used to order the corresponding elements of names.
", "templateType": "anything"}, "sorted": {"name": "sorted", "group": "Ungrouped variables", "definition": "map(\n x[0],\n x,\n sort_by(1,zip(names,order))\n)", "description": "[name,order]
sort_by
.