def count_non_overlapping(s, substr, start): Return the number of non-overlapping occurrences of substr in s starting from the index start. You can not use str method s.count. return 0 def count_non_overlapping_m(s, substr, start): Return the number of non-overlapping occurrences of substr in s starting from the index start. You must use a one-liner implementation by using s.count(). return Ø def find_smallest(t): Return the smallest element in given list t. Return None if t is empty return t[0] def myfilter(t, cond): t is a list, cond(x) is a boolean function that returns True or False given an element x in t. Return a new list that only includes element x from t such cond(x) is True. return t For the implementation of count_non_overlapping(), you CAN NOT use any string method such as s.find(), s.count s.index(). Be aware of handling of start index in particular when it is negative. Be aware that you are to find non- overlapping matches.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

python.

To run and test your program:
~/cmpsc131python-userid$cd lab6
~/cmpsc131python-userid/lab6$python3 -i lab6.py
Expected output:
$ python3 lab6.py
Enter a string: banana
Enter a substring to count: a
Entera starting index: -3
a occurred in banana 2 times starting from index -3.
a occurred in banana 2 times starting from index -3.
Testing find_smallest:
min in [5, 8, 10, 2, 7] is 2
min in ['hello', 'apple', 'banana', 'world'] is apple
Testing myfilter:
filering ['a', 'apple', 'racecar', 'hannah', 'banana'] with is_palindrome is ['a', 'racecar', 'hannah']
filtering [0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48] with is_even is [0, 6, 12, 18, 24, 30, 36, 42, 48]
$python3 lab6.py
Enter a string: banana
Enter a substring to count: ana
Entera starting index: 1
ana occurred in banana 1 times starting from index 1.
ana occurred in banana 1 times starting from index 1.
[... the same in all runs for find_smallest and myfilter.]
Transcribed Image Text:To run and test your program: ~/cmpsc131python-userid$cd lab6 ~/cmpsc131python-userid/lab6$python3 -i lab6.py Expected output: $ python3 lab6.py Enter a string: banana Enter a substring to count: a Entera starting index: -3 a occurred in banana 2 times starting from index -3. a occurred in banana 2 times starting from index -3. Testing find_smallest: min in [5, 8, 10, 2, 7] is 2 min in ['hello', 'apple', 'banana', 'world'] is apple Testing myfilter: filering ['a', 'apple', 'racecar', 'hannah', 'banana'] with is_palindrome is ['a', 'racecar', 'hannah'] filtering [0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48] with is_even is [0, 6, 12, 18, 24, 30, 36, 42, 48] $python3 lab6.py Enter a string: banana Enter a substring to count: ana Entera starting index: 1 ana occurred in banana 1 times starting from index 1. ana occurred in banana 1 times starting from index 1. [... the same in all runs for find_smallest and myfilter.]
def count_non_overlapping(s, substr, start):
II II ||
Return the number of non-overlapping occurrences of substr in s
starting from the index start.
You can not use str method s.count.
return 0
def count_non_overlapping_m(s, substr, start):
II II ||
Return the number of non-overlapping occurrences of substr in s
starting from the index start.
You must use a one-liner implementation by using s.count().
II II ||
return 0
def find_smallest(t):
Return the smallest element in given list t.
Return None if t is empty
return t[0]
def myfilter(t, cond):
t is a list, cond(x) is a boolean function that returns True or False
given an element x in t.
Return a new list that only includes element x from t such cond(x) is True.
II II ||
return t
For the implementation of count_non_overlapping(), you CAN NOT use any string method such as s.find(), s.count(),
s.index(). Be aware of handling of start index in particular when it is negative. Be aware that you are to find non-
overlapping matches.
Transcribed Image Text:def count_non_overlapping(s, substr, start): II II || Return the number of non-overlapping occurrences of substr in s starting from the index start. You can not use str method s.count. return 0 def count_non_overlapping_m(s, substr, start): II II || Return the number of non-overlapping occurrences of substr in s starting from the index start. You must use a one-liner implementation by using s.count(). II II || return 0 def find_smallest(t): Return the smallest element in given list t. Return None if t is empty return t[0] def myfilter(t, cond): t is a list, cond(x) is a boolean function that returns True or False given an element x in t. Return a new list that only includes element x from t such cond(x) is True. II II || return t For the implementation of count_non_overlapping(), you CAN NOT use any string method such as s.find(), s.count(), s.index(). Be aware of handling of start index in particular when it is negative. Be aware that you are to find non- overlapping matches.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Introduction to computer system
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education