mirror of
https://github.com/donnemartin/data-science-ipython-notebooks.git
synced 2024-03-22 13:30:56 +08:00
Added sorted snippets.
This commit is contained in:
parent
661b71035b
commit
a152e86d58
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:80ff2bfd9335618eb25e15d2708a5703a0249ba8c3beb2c78875bd7a0b8c8e3c"
|
||||
"signature": "sha256:a7df82135c56674dfb56c48aead92e0e7fe6ce1bdc8cdbc48eb820284aa24f65"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
|
@ -1002,6 +1002,88 @@
|
|||
}
|
||||
],
|
||||
"prompt_number": 35
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## sorted"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Return a new sorted list from the elements of a sequence"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"sorted([2, 5, 1, 8, 7, 9])"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"metadata": {},
|
||||
"output_type": "pyout",
|
||||
"prompt_number": 36,
|
||||
"text": [
|
||||
"[1, 2, 5, 7, 8, 9]"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 36
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"sorted('foo bar baz')"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"metadata": {},
|
||||
"output_type": "pyout",
|
||||
"prompt_number": 37,
|
||||
"text": [
|
||||
"[' ', ' ', 'a', 'a', 'b', 'b', 'f', 'o', 'o', 'r', 'z']"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 37
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"It's common to get a sorted list of unique elements by combining sorted and set"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"seq = [2, 5, 1, 8, 7, 9, 9, 2, 5, 1, (4, 2), (1, 2), (1, 2)]\n",
|
||||
"sorted(set(seq))"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"metadata": {},
|
||||
"output_type": "pyout",
|
||||
"prompt_number": 38,
|
||||
"text": [
|
||||
"[1, 2, 5, 7, 8, 9, (1, 2), (4, 2)]"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 38
|
||||
}
|
||||
],
|
||||
"metadata": {}
|
||||
|
|
Loading…
Reference in New Issue
Block a user