mirror of
https://github.com/rasbt/python_reference.git
synced 2025-01-18 07:17:06 +00:00
palindrom upd
This commit is contained in:
parent
add8b700d9
commit
4d8752c904
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:2d59017b21afaeadb093fa062632884c6d9d2e32933483326066a3219fba638c"
|
||||
"signature": "sha256:6ea19109869c82ee989c8ea0599ec49401e74246a542ad0b7b05f6ef464bda19"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
|
@ -45,6 +45,11 @@
|
|||
" letters = [c for c in my_str.lower() if c in LOWERS]\n",
|
||||
" return letters == letters[::-1]\n",
|
||||
"\n",
|
||||
"LOWERS = set(string.ascii_lowercase)\n",
|
||||
"def palindrome_stringlib2(my_str):\n",
|
||||
" letters = [c for c in my_str.lower() if c in LOWERS]\n",
|
||||
" return letters == letters[::-1]\n",
|
||||
"\n",
|
||||
"def palindrome_isalpha(my_str):\n",
|
||||
" stripped_str = [l for l in my_str.lower() if l.isalpha()]\n",
|
||||
" return stripped_str == stripped_str[::-1]\n",
|
||||
|
@ -74,7 +79,7 @@
|
|||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"prompt_number": 7
|
||||
"prompt_number": 10
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
|
@ -86,6 +91,7 @@
|
|||
"%timeit palindrome_short(test_str)\n",
|
||||
"%timeit palindrome_regex(test_str)\n",
|
||||
"%timeit palindrome_stringlib(test_str)\n",
|
||||
"%timeit palindrome_stringlib2(test_str)\n",
|
||||
"%timeit palindrome_isalpha(test_str)\n",
|
||||
"\n",
|
||||
"print('\\n\\nfunctions considering all characters (case-sensitive)')\n",
|
||||
|
@ -109,7 +115,7 @@
|
|||
"stream": "stdout",
|
||||
"text": [
|
||||
"\n",
|
||||
"10000 loops, best of 3: 20.2 \u00b5s per loop"
|
||||
"100000 loops, best of 3: 19.9 \u00b5s per loop"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -117,7 +123,7 @@
|
|||
"stream": "stdout",
|
||||
"text": [
|
||||
"\n",
|
||||
"100000 loops, best of 3: 12 \u00b5s per loop"
|
||||
"100000 loops, best of 3: 13.5 \u00b5s per loop"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -125,7 +131,15 @@
|
|||
"stream": "stdout",
|
||||
"text": [
|
||||
"\n",
|
||||
"100000 loops, best of 3: 9.45 \u00b5s per loop"
|
||||
"100000 loops, best of 3: 8.58 \u00b5s per loop"
|
||||
]
|
||||
},
|
||||
{
|
||||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"\n",
|
||||
"100000 loops, best of 3: 9.42 \u00b5s per loop"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -136,7 +150,7 @@
|
|||
"\n",
|
||||
"\n",
|
||||
"functions considering all characters (case-sensitive)\n",
|
||||
"1000000 loops, best of 3: 498 ns per loop"
|
||||
"1000000 loops, best of 3: 508 ns per loop"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -144,7 +158,7 @@
|
|||
"stream": "stdout",
|
||||
"text": [
|
||||
"\n",
|
||||
"100000 loops, best of 3: 3.28 \u00b5s per loop"
|
||||
"100000 loops, best of 3: 3.08 \u00b5s per loop"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -152,7 +166,7 @@
|
|||
"stream": "stdout",
|
||||
"text": [
|
||||
"\n",
|
||||
"1000000 loops, best of 3: 478 ns per loop"
|
||||
"1000000 loops, best of 3: 480 ns per loop"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -163,7 +177,7 @@
|
|||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 8
|
||||
"prompt_number": 11
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
|
|
Loading…
Reference in New Issue
Block a user