Skip to content

Instantly share code, notes, and snippets.

@ZechCodes
Created June 24, 2020 01:51
Show Gist options
  • Save ZechCodes/85befee16c2cf4a3374cd4fdfcb62e2a to your computer and use it in GitHub Desktop.
Save ZechCodes/85befee16c2cf4a3374cd4fdfcb62e2a to your computer and use it in GitHub Desktop.

Challenge 37 - Match the Last Item

Create a function that takes a list of items and checks if the last item matches the rest of the list.

Examples

match_last_item(["rsq", "6hi", "g", "rsq6hig"]) ➞ True
# The last item is the rest joined.

match_last_item([1, 1, 1, "11"]) ➞ False
# The last item should be "111".

match_last_item([8, "thunder", True, "8thunderTrue"]) ➞ True

Notes

  • The list is always filled with items
import unittest
from typing import Any, List
def match_last_item(items: List[Any]) -> bool:
return False # Put your code here!!!
class TestMatchLastItem(unittest.TestCase):
def test_1(self):
self.assertEqual(match_last_item(['rsq', '6hi', 'g', 'rsq6hig']), True)
def test_2(self):
self.assertEqual(match_last_item([0, 1, 2, 3, 4, 5, '12345']), False)
def test_3(self):
self.assertEqual(match_last_item(['for', 'mi', 'da', 'bel', 'formidable']), False)
def test_4(self):
self.assertEqual(match_last_item([8, 'thunder', True, '8thunderTrue']), True)
def test_5(self):
self.assertEqual(match_last_item([ 1, 1, 1, '11' ]), False)
def test_6(self):
self.assertEqual(match_last_item(['tocto','G8G','xtohkgc','3V8','ctyghrs',100.88,'fyuo','Q','toctoG8Gxtohkgc3V8ctyghrs100.88fyuoQ']), True)
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment