Skip to content

Commit d71c284

Browse files
committed
fixed palindrome issue
1 parent cbe16a9 commit d71c284

File tree

2 files changed

+58
-10
lines changed

2 files changed

+58
-10
lines changed

.ipynb_checkpoints/Functions and Methods Homework - Solutions-checkpoint.ipynb

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,19 +254,43 @@
254254
},
255255
{
256256
"cell_type": "code",
257-
"execution_count": 19,
257+
"execution_count": 5,
258258
"metadata": {
259259
"collapsed": true
260260
},
261261
"outputs": [],
262262
"source": [
263263
"def palindrome(s):\n",
264-
" return s == s[::-1]"
264+
" \n",
265+
" s = s.replace(' ','') # This replaces all spaces \" \" with no space ''. (Fixes issues with sentence like strings)\n",
266+
" return s == s[::-1] # Check through slicing"
265267
]
266268
},
267269
{
268270
"cell_type": "code",
269-
"execution_count": 20,
271+
"execution_count": 7,
272+
"metadata": {
273+
"collapsed": false
274+
},
275+
"outputs": [
276+
{
277+
"data": {
278+
"text/plain": [
279+
"True"
280+
]
281+
},
282+
"execution_count": 7,
283+
"metadata": {},
284+
"output_type": "execute_result"
285+
}
286+
],
287+
"source": [
288+
"palindrome('nurses run')"
289+
]
290+
},
291+
{
292+
"cell_type": "code",
293+
"execution_count": 8,
270294
"metadata": {
271295
"collapsed": false
272296
},
@@ -277,13 +301,13 @@
277301
"True"
278302
]
279303
},
280-
"execution_count": 20,
304+
"execution_count": 8,
281305
"metadata": {},
282306
"output_type": "execute_result"
283307
}
284308
],
285309
"source": [
286-
"palindrome('helleh')"
310+
"palindrome('abcba')"
287311
]
288312
},
289313
{

Functions and Methods Homework - Solutions.ipynb

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,19 +254,43 @@
254254
},
255255
{
256256
"cell_type": "code",
257-
"execution_count": 19,
257+
"execution_count": 5,
258258
"metadata": {
259259
"collapsed": true
260260
},
261261
"outputs": [],
262262
"source": [
263263
"def palindrome(s):\n",
264-
" return s == s[::-1]"
264+
" \n",
265+
" s = s.replace(' ','') # This replaces all spaces \" \" with no space ''. (Fixes issues with sentence like strings)\n",
266+
" return s == s[::-1] # Check through slicing"
265267
]
266268
},
267269
{
268270
"cell_type": "code",
269-
"execution_count": 20,
271+
"execution_count": 7,
272+
"metadata": {
273+
"collapsed": false
274+
},
275+
"outputs": [
276+
{
277+
"data": {
278+
"text/plain": [
279+
"True"
280+
]
281+
},
282+
"execution_count": 7,
283+
"metadata": {},
284+
"output_type": "execute_result"
285+
}
286+
],
287+
"source": [
288+
"palindrome('nurses run')"
289+
]
290+
},
291+
{
292+
"cell_type": "code",
293+
"execution_count": 8,
270294
"metadata": {
271295
"collapsed": false
272296
},
@@ -277,13 +301,13 @@
277301
"True"
278302
]
279303
},
280-
"execution_count": 20,
304+
"execution_count": 8,
281305
"metadata": {},
282306
"output_type": "execute_result"
283307
}
284308
],
285309
"source": [
286-
"palindrome('helleh')"
310+
"palindrome('abcba')"
287311
]
288312
},
289313
{

0 commit comments

Comments
 (0)