Skip to content

Commit 0f112f7

Browse files
committed
another probelm fix
1 parent 1efa0fa commit 0f112f7

4 files changed

+52
-32
lines changed

03-Methods and Functions/.ipynb_checkpoints/03-Function Practice Exercises-checkpoint.ipynb

+7-5
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,13 @@
328328
"cell_type": "markdown",
329329
"metadata": {},
330330
"source": [
331-
"#### LAUGHTER: Write a function that counts the number of times a given pattern appears in a string, *including overlap*\n",
331+
"### Find 33: \n",
332332
"\n",
333-
" laughter('hah','hahahah') --> 3\n",
333+
"Given a list of ints, return True if the array contains a 3 next to a 3 somewhere.\n",
334334
"\n",
335-
"Note that `'hahahah'.count('hah')` only returns 2."
335+
" has_33([1, 3, 3]) → True\n",
336+
" has_33([1, 3, 1, 3]) → False\n",
337+
" has_33([3, 1, 3]) → False"
336338
]
337339
},
338340
{
@@ -343,7 +345,7 @@
343345
},
344346
"outputs": [],
345347
"source": [
346-
"def laughter(pattern,text):\n",
348+
"def has_33(pattern,text):\n",
347349
" pass"
348350
]
349351
},
@@ -356,7 +358,7 @@
356358
"outputs": [],
357359
"source": [
358360
"# Check\n",
359-
"laughter('hah','hahahah')"
361+
"has_33([1, 3, 3])"
360362
]
361363
},
362364
{

03-Methods and Functions/.ipynb_checkpoints/04-Function Practice Exercises - Solutions-checkpoint.ipynb

+19-11
Original file line numberDiff line numberDiff line change
@@ -454,11 +454,13 @@
454454
"cell_type": "markdown",
455455
"metadata": {},
456456
"source": [
457-
"#### LAUGHTER: Write a function that counts the number of times a given pattern appears in a string, *including overlap*\n",
457+
"### Find 33: \n",
458458
"\n",
459-
" laughter('hah','hahahah') --> 3\n",
459+
"Given a list of ints, return True if the array contains a 3 next to a 3 somewhere.\n",
460460
"\n",
461-
"Note that `'hahahah'.count('hah')` only returns 2."
461+
" has_33([1, 3, 3]) → True\n",
462+
" has_33([1, 3, 1, 3]) → False\n",
463+
" has_33([3, 1, 3]) → False"
462464
]
463465
},
464466
{
@@ -469,12 +471,16 @@
469471
},
470472
"outputs": [],
471473
"source": [
472-
"def laughter(pattern,text):\n",
473-
" out = 0\n",
474-
" for x in range(len(text)-2):\n",
475-
" if text[x:x+len(pattern)] == pattern:\n",
476-
" out += 1\n",
477-
" return out"
474+
"def has_33(nums):\n",
475+
" for i in range(0, len(nums)-1):\n",
476+
" \n",
477+
" # nicer looking alternative in commented code\n",
478+
" #if nums[i] == 2 and nums[i+1] == 2:\n",
479+
" \n",
480+
" if nums[i:i+2] == [2,2]:\n",
481+
" return True \n",
482+
" \n",
483+
" return False"
478484
]
479485
},
480486
{
@@ -495,7 +501,7 @@
495501
],
496502
"source": [
497503
"# Check\n",
498-
"laughter('hah','hahahah')"
504+
"has_33([1, 3, 3])"
499505
]
500506
},
501507
{
@@ -983,7 +989,9 @@
983989
"cell_type": "markdown",
984990
"metadata": {},
985991
"source": [
986-
"### Just for fun:\n",
992+
"-----\n",
993+
"### Just for fun, not a real problem :)\n",
994+
"\n",
987995
"#### PRINT BIG: Write a function that takes in a single letter, and returns a 5x5 representation of that letter\n",
988996
" print_big('a')\n",
989997
" \n",

03-Methods and Functions/03-Function Practice Exercises.ipynb

+7-5
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,13 @@
328328
"cell_type": "markdown",
329329
"metadata": {},
330330
"source": [
331-
"#### LAUGHTER: Write a function that counts the number of times a given pattern appears in a string, *including overlap*\n",
331+
"### Find 33: \n",
332332
"\n",
333-
" laughter('hah','hahahah') --> 3\n",
333+
"Given a list of ints, return True if the array contains a 3 next to a 3 somewhere.\n",
334334
"\n",
335-
"Note that `'hahahah'.count('hah')` only returns 2."
335+
" has_33([1, 3, 3]) → True\n",
336+
" has_33([1, 3, 1, 3]) → False\n",
337+
" has_33([3, 1, 3]) → False"
336338
]
337339
},
338340
{
@@ -343,7 +345,7 @@
343345
},
344346
"outputs": [],
345347
"source": [
346-
"def laughter(pattern,text):\n",
348+
"def has_33(pattern,text):\n",
347349
" pass"
348350
]
349351
},
@@ -356,7 +358,7 @@
356358
"outputs": [],
357359
"source": [
358360
"# Check\n",
359-
"laughter('hah','hahahah')"
361+
"has_33([1, 3, 3])"
360362
]
361363
},
362364
{

03-Methods and Functions/04-Function Practice Exercises - Solutions.ipynb

+19-11
Original file line numberDiff line numberDiff line change
@@ -454,11 +454,13 @@
454454
"cell_type": "markdown",
455455
"metadata": {},
456456
"source": [
457-
"#### LAUGHTER: Write a function that counts the number of times a given pattern appears in a string, *including overlap*\n",
457+
"### Find 33: \n",
458458
"\n",
459-
" laughter('hah','hahahah') --> 3\n",
459+
"Given a list of ints, return True if the array contains a 3 next to a 3 somewhere.\n",
460460
"\n",
461-
"Note that `'hahahah'.count('hah')` only returns 2."
461+
" has_33([1, 3, 3]) → True\n",
462+
" has_33([1, 3, 1, 3]) → False\n",
463+
" has_33([3, 1, 3]) → False"
462464
]
463465
},
464466
{
@@ -469,12 +471,16 @@
469471
},
470472
"outputs": [],
471473
"source": [
472-
"def laughter(pattern,text):\n",
473-
" out = 0\n",
474-
" for x in range(len(text)-2):\n",
475-
" if text[x:x+len(pattern)] == pattern:\n",
476-
" out += 1\n",
477-
" return out"
474+
"def has_33(nums):\n",
475+
" for i in range(0, len(nums)-1):\n",
476+
" \n",
477+
" # nicer looking alternative in commented code\n",
478+
" #if nums[i] == 2 and nums[i+1] == 2:\n",
479+
" \n",
480+
" if nums[i:i+2] == [2,2]:\n",
481+
" return True \n",
482+
" \n",
483+
" return False"
478484
]
479485
},
480486
{
@@ -495,7 +501,7 @@
495501
],
496502
"source": [
497503
"# Check\n",
498-
"laughter('hah','hahahah')"
504+
"has_33([1, 3, 3])"
499505
]
500506
},
501507
{
@@ -983,7 +989,9 @@
983989
"cell_type": "markdown",
984990
"metadata": {},
985991
"source": [
986-
"### Just for fun:\n",
992+
"-----\n",
993+
"### Just for fun, not a real problem :)\n",
994+
"\n",
987995
"#### PRINT BIG: Write a function that takes in a single letter, and returns a 5x5 representation of that letter\n",
988996
" print_big('a')\n",
989997
" \n",

0 commit comments

Comments
 (0)