Question: In Python Please: Have to use dictionaries here is the test code: Part B (longest_consecutive_repeating char) now needs to account for the edge case where

In Python Please: Have to use dictionaries  In Python Please: Have to use dictionaries here is the test
code: Part B (longest_consecutive_repeating char) now needs to account for the edge
case where two characters have the same consecutive repeat length. The return
here is the test code:
value should now be a list containing all characters with the longest

Part B (longest_consecutive_repeating char) now needs to account for the edge case where two characters have the same consecutive repeat length. The return value should now be a list containing all characters with the longest consecutive repeat. For example, the longest consecutive_repeating charaabbccd') would return ['a': 'b'c'l (order doesn't matter). You must use a dictionary to accomplish this. Note that our existing test file won't work with these changes. We will be updating that in the next step. Proje- 40 42 43 44 # Part B. Longest_consecutive_repeating char # Define a function longest_consecutive_repeating char(s) that takes A# a strings and returns the character that has the longest consecutive repeat. edef Longest consecutive_repeating_char(s): s = list(s) 1 = len(s) cnt = 1 # declaring the dictionary to keep track of frequencies umap = {} 45 46 47 48 49 50 51 52 53 54 55 # counting frequency of every char for 1 in range, 1 - 1): if s(1) != s[1 + 1): if (s[1] in umap) and umap[s(1)] > cnt: continue else: umap(s[1]] = cnt cnt = 1 else: cnt = cnt + 1 56 57 58 59 60 61 umap(s(1 - 1)] = cnt 62 63 64 65 66 67 68 # finding the maximum frequency maximum = -1 Tor k, v in umap.items(): 11 V > maximum: maximum =V 50 51 DD 52 53 54 55 # counting frequency for i in range(, 1 - 1): if s[i] != s[i + 1]: it (s[i] in umap) and umap[s[1]] > cnt: continue else: umap(s[1]) = cnt cnt = 1 else: cnt = cnt + 1 D * 56 57 58 59 60 61 umap(s(1 - 1)] = cnt 62 63 64 65 66 # finding the maximum frequency maximum = -1 for k, v in umap.Items(): 11 V > maximum: maximum = V 67 68 69 70 71 72 # adding the chars to the list with max frequency lst = [] for k, v in umap.items(): 11 v = maximum: Ist.append(K) 73 e 74 e return Lst 75 76 77 longest consecutive repeating det test_longest_consecutive_repeating_char(self): # Default cases self.assertEqual (pythonBasics2.longest consecutive_repeating_char('aaa'), ('a']) self.assertEqual (pythonBasics2.longest_consecutive_repeating_char('abba'), ('b']) self.assertEqual (pythonBasics2.longest_consecutive_repeating.char('caagdda'), ('d']) selt.assertEqual (pythonBasics2.longest_consecutive_repeating_char( 'aaaffftttt'), I't']) selt.assertEqual(pythonBasics2. Longest consecutive_repeating.char('sababbacccca'), ('c']) selt.assertEqual (pythonBasics2.longest consecutive_repeating-char('ddabab'), ('d']) self.assertEqual (pythonBasics2.longest consecutivo_repeating.char('cane'), ('a']) # Multiple outputs self assertEqual(set(pythonBasics2.Longest consecutive_repeating.char('saade')('a', 'c'}) self.assertEqual(set(pythonBasics2.longest consecutive_repeating.char("bbbaaaceeet')) {'a', 'b', 'e')) self assertEqual(set (pythonBasics2.longest consecutive_repeating.char('abeddefash:1'), ('d', '9'>) selt.assertEqual(set(pythonBasic 2. Longest consecutive_repeating.char( 'aabbbocddddofaaghhhh')). ('d', '.' det test_is_palindrom(self): self.assertEqual (pythonBasics2.is_palindrome("Hello"). False) an pythoniasis Test File "/ral/51556 Letos.com.Zaython2", line 30, in test_longest consecutive_repeating e solt.assertEqual(pythonBasics2. Longest consecutive_repeating.char('abba'), ('b')) AssertionError: Lists differ: t'a') [*] First differing element 0: L'a'1 De Tamil Pharm 2020.1.3 valatie / de today20 PM

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!