Skip to content

Instantly share code, notes, and snippets.

@lkluft
Last active July 27, 2016 09:34
Show Gist options
  • Save lkluft/cdae8dbfc5dfd96eed322cc08966a9c0 to your computer and use it in GitHub Desktop.
Save lkluft/cdae8dbfc5dfd96eed322cc08966a9c0 to your computer and use it in GitHub Desktop.
Sorting several lists alongside.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {
"trusted": true,
"collapsed": false,
"ExecuteTime": {
"start_time": "2016-07-27T11:34:12.042773",
"end_time": "2016-07-27T11:34:12.049842"
}
},
"cell_type": "code",
"source": "# Create three lists of same lengths.\nl1 = ['two', 'four', 'three', 'one']\nl2 = ['zwei', 'vier', 'drei', 'eins']\nl3 = [2, 4, 3, 1]\n\n# Sort all lists depending on the entries of the third list.\nsl1, sl2, sl3 = [list(t) for t in zip(*sorted(zip(l1, l2, l3), key=lambda x: x[2]))]\n\nprint(sl1, sl2, sl3)",
"execution_count": 1,
"outputs": [
{
"output_type": "stream",
"text": "['one', 'two', 'three', 'four'] ['eins', 'zwei', 'drei', 'vier'] [1, 2, 3, 4]\n",
"name": "stdout"
}
]
}
],
"metadata": {
"_draft": {
"nbviewer_url": "https://gist.github.com/cdae8dbfc5dfd96eed322cc08966a9c0"
},
"anaconda-cloud": {},
"toc": {
"toc_cell": false,
"toc_threshold": 6,
"toc_window_display": false,
"toc_number_sections": true
},
"gist": {
"id": "cdae8dbfc5dfd96eed322cc08966a9c0",
"data": {
"description": "Sorting several lists alongside.",
"public": true
}
},
"kernelspec": {
"name": "Python [Root]",
"display_name": "Python [Root]",
"language": "python"
},
"language_info": {
"nbconvert_exporter": "python",
"codemirror_mode": {
"version": 3,
"name": "ipython"
},
"file_extension": ".py",
"pygments_lexer": "ipython3",
"version": "3.5.2",
"mimetype": "text/x-python",
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment