Question: class StringList(list): #your code here #sample object creation l1 = StringList(['A', 'B', 'Test']) l2 = StringList(['A', 1, 'FREE', 2]) print('l1 valid? ', l1.isvalid()) print('l2 valid?

 class StringList(list): #your code here #sample object creation l1 = StringList(['A',

'B', 'Test']) l2 = StringList(['A', 1, 'FREE', 2]) print('l1 valid? ', l1.isvalid())

class StringList(list): #your code here

#sample object creation l1 = StringList(['A', 'B', 'Test']) l2 = StringList(['A', 1, 'FREE', 2]) print('l1 valid? ', l1.isvalid()) print('l2 valid? ', l2.isvalid()) print(l1) print(l2)

Problem Statement: In this assignment, you will extend built-in class list. The extended class name is 'StringList, class which will check if a newly created list is valid or not. If the list is valid then it will print all the elements of the list. The definition of valid/invalid is provided below This class will have following methods Method name Description Checks if all the elements in a newly created list is 'str' datatype or not. Use isinstance(| function to check if an element is 'str' type. Example syntax: >>>isinstance('Hi', str) returns True Checks if a StringList object is valid, if its valid then will concatenate all the strings and return the new string. Otherwise returns 'Invalid' message Parameter None Return Returns true if the string is valid otherwise returns false. isvalid(self) (self) None Returns concatenated string if StringList object is valid otherwise returns 'Invalid' message str -- Object Creation/Instantiation: You need to create two objects '"11' and '12'. A sample code has been provided in the template file. 1 StringList(['A', 'B', Test']) 2 StringList(['A', 1, 'FREE', 2]) #valid string list #invalid string list Sample l/0: 1 StringList (['A', 'B', Test]) 12-StringList[iA, 1, FREE, 21) print(11 valid?', 11.isvalid()) print(12 valid? ', 12.isvalid()) print(l1) print(12) 1 valid? True 2 valid? False ABTest Invalid string list

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!