- Part A Write A Function String Section S1 S2 The Function Gets Two Strings S1 S2 As Parameters The Strings Are Made 1 (127.14 KiB) Viewed 82 times
Part A Write a function: string_section (s1, s2) The function gets two strings s1,s2 as parameters. The strings are made
-
- Posts: 43759
- Joined: Sat Aug 07, 2021 7:38 am
Part A Write a function: string_section (s1, s2) The function gets two strings s1,s2 as parameters. The strings are made
question should be in the file hw4q1.py.
Part A Write a function: string_section (s1, s2) The function gets two strings s1,s2 as parameters. The strings are made of English letters and are sorted alphabetically from left to right. The function returns a sorted string that includes only common letters from s1 and s2. Each letter appears in the result as many times as it appears in both strings. Time complexity requirement: O(n1+n2) n1 = len(s1), n2 = len(s2). Examples: s1 s2 return 'cde' 'cde' 'abcdefg' 'booooozz' 'Ozzz' 'ozz' 'abcd' 'efgh' 'hhhh' 'hhhh' 'hhhh' Part B Write a program that gets as input two strings from the user, one after the other. The program prints the result of string_section (s1,s2) by calling the function with the input strings. Notes: ● Strings s1,s2 are composed of lowercase English letters only. In Python, you can use: 'a' < 'b' True 'c'> 'd' → False ● Do not use any input prompts or unnecessary prints. Try to write efficient code. Avoid unnecessary loops and statements. Both parts of the