Checkpoint 9.18.1.
Write a function
add_to_new_list
that takes in a list of strings, lst
, as a parameter and creates a new list with the length of lst
and the first element of lst
three times. For example, add_to_new_list(["1","2","3"])
would return [3, '111']
.
Solution.
Write a function add_to_new_list that takes in a list of strings, lst, as a parameter and creates a new list with the length of lst and the first element of lst three times. For example, add_to_new_list(["1","2","3"]) would return [3, '111'].
def add_to_new_list(lst):
new_list = []
new_list.append(len(lst))
new_list.append(lst[0] * 3)
return new_list
=====
from unittest.gui import TestCaseGui
class myTests(TestCaseGui):
def testOne(self):
self.assertEqual(add_to_new_list(['1','2','3']), [3, '111'], "add_to_new_list(['1','2','3'])")
self.assertEqual(add_to_new_list(['0','0','0','0']), [4, '000'], "add_to_new_list(['0','0','0','0'])")
self.assertEqual(add_to_new_list(['10.2','0.0','100','-2']), [4, '10.210.210.2'], "add_to_new_list(['10.2','0.0','100','-2'])")
myTests().main()