Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function jscore(s1, s2) that takes two strings s1 and s2 as inputs and returns the Jotto score of s1 compared with s2 i.e.,

  1. Write a function jscore(s1, s2) that takes two strings s1 and s2 as inputs and returns the Jotto score of s1 compared with s2 i.e., the number of characters in s1 that are shared by s2. The positions and the order of the shared characters within each string do not matter. Repeated letters are counted multiple times, as long as they appear multiple times in both strings. For example:

    >>> jscore('diner', 'syrup') # just the 'r' result: 1 >>> jscore('always', 'bananas') # two 'a's and one 's' result: 3 >>> jscore('always', 'walking') # one 'a', 'l', and 'w' result: 3 >>> jscore('recursion', 'excursion') # everything but the 'r' in s1 is shared by s2 result: 8 >>> jscore('recursion', '') # 0 because s2 is empty result: 0 

    Notes/hints:

    • Unlike the words in traditional Jotto, which always have five letters, there are no restrictions on the lengths of the input strings s1 and s2.

    • If either s1 or s2 is the empty string, the Jotto score is 0.

    • You can write the function any way you like as long as you use functional programming.

    • We encourage you to consider using one or more helper functions. In particular, one possible approach involves using a function like the rem_first function that we considered in lecture. However, you would need to rework that function so that it operates on a string rather than a list.

    • This line turns out to be useful:

      if s1[0] in s2: 

Submitting your work for P

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Fred R. McFadden, Jeffrey Slater, Mary B. Prescott

5th Edition

0805360549, 978-0805360547

Students also viewed these Databases questions

Question

4. Identify the supernatural aid in The Wizard of Oz.

Answered: 1 week ago