Created
May 25, 2020 04:10
-
-
Save chinmaythosar/54283e48327ac63f199031f9f25bb2d2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
import sys | |
class Solution: | |
def merge(self, original, add, delete): | |
#Merge original and add in new string | |
out = original + add | |
#delete string | |
for x in delete: | |
for y in out: | |
if (id(x) == id(y)): | |
out.remove(y) | |
#remove duplicates | |
out = list(set(out)) | |
#sort reverse - also implicitly sorts alphabetical | |
out.sort(reverse=True) | |
return out | |
class Tests(unittest.TestCase): | |
def test_1(self): | |
out = ['thref', 'three', 'six', 'one'] | |
original = ['one', 'two', 'three'] | |
add = ['one', 'two', 'five', 'six','thref'] | |
delete = ['two', 'five'] | |
test1 = Solution() | |
self.assertEqual(test1.merge(original,add,delete),out) | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment