Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Another set operation exercise Write a function character_set_counts (string_1,

ID: 3757214 • Letter: A

Question

Another set operation exercise Write a function character_set_counts (string_1, string_2, string_3) that returns a count of the number of distinct characters that are common to both strings string_1 and string_2 but are absent from the string string 3. For example, if string_1 is "abcz", string_2 is "daze", and string 3 is "doze", then the answer is 1 because 'a' and Z' are common to string_1 and string _2, but z is present in string_3, leaving only 'a You're expected to solve this using sets. Hint: if you don't know how to make a set of characters from a string, maybe you shouldn't have skipped the introduction? For example: Test Result answer character_set_counts ('abcdef', 'bcd', 'ace 2 print(answer)

Explanation / Answer

def character_set_counts(string_1, string_2, string_3): count = 0 for c in string_1: if c in string_2 and c not in string_3: count += 1 return count print(character_set_counts('abcdef', 'bcd', 'ace'))

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote