Skip to content

Instantly share code, notes, and snippets.

@chinmaythosar
Created May 25, 2020 04:10
Show Gist options
  • Save chinmaythosar/54283e48327ac63f199031f9f25bb2d2 to your computer and use it in GitHub Desktop.
Save chinmaythosar/54283e48327ac63f199031f9f25bb2d2 to your computer and use it in GitHub Desktop.
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