So I am taking some challenges to help me with learning python but I am having issues with this one on data structures.
I am suppose to write a function for removing duplicates in a string and then return the new string with the number of strings dropped. My code does this quite alright but I still get an error. something about incorrect output type, and assertError.
this is the exact error I am getting:
1 . test_output_1
Failure in line 16, in test_output_1 self.assertEqual(self.result1,
('abc', 5), msg='Incorrect output') AssertionError: Incorrect output
this is the test
import unittest
class RemoveDuplicatesTestCases(unittest.TestCase):
def setUp(self):
self.result1 = remove_duplicates('aaabbbac')
self.result2 = remove_duplicates('a')
self.result3 = remove_duplicates('thelexash')
def test_output_1(self):
self.assertIsInstance(self.result1, tuple, msg='Incorrect output type')
self.assertEqual(self.result1, ('abc', 5), msg='Incorrect output')
def test_output_2(self):
self.assertIsInstance(self.result2, tuple, msg='Incorrect output type')
self.assertEqual(self.result2, ('a', 0), msg='Incorrect output')
def test_output_3(self):
self.assertIsInstance(self.result3, tuple, msg='Incorrect output type')
self.assertEqual(self.result3, ('aehlstx', 2), msg='Incorrect output')
and here is my code
def remove_duplicates(string):
assert (type(string) == str)
new_string = ''.join(set(string))
length = len(string) - len(new_string)
for char in string:
if char in "abcdefghijklmnopqrstuvwxyz":
return (new_string, int(length))
return (new_string, length)
I am kinda new to the whole python thingy
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
I have fixed it