Is it Well Formatted? (Problem 34) - InfyTQ Solution in Python
Is it Well Formatted? (Problem 34)
InfyTQ Solution in Python
PROBLEM STATEMENT
[Cornell University CS1110 Final Exam 2014 Spring]
Write a recursive python function which returns True if the input is well-formatted with respect to the list labels. Else it should return False.
We say that an input is well-formatted with respect to the labels if:
(a) input item is a list
(b) input item has length at least two
(c) input’s first item is in the list labels
(d) each of the remaining items in input is either a string or a well-formatted list
Write a recursive python function which returns True if the input is well-formatted with respect to the list labels. Else it should return False.
We say that an input is well-formatted with respect to the labels if:
(a) input item is a list
(b) input item has length at least two
(c) input’s first item is in the list labels
(d) each of the remaining items in input is either a string or a well-formatted list
nput item | list label | Expected output |
---|---|---|
['VP', ['V', 'eat']] | ['VP', 'V'] | True |
['NP', ['N', 'a', 'or', 'b'], 'c'] | ['NP', 'V', 'N'] | True |
[1, [2, 'oui', [1, 'no']], 'no'] | [1,2] | True |
['VP', ['V', 'eat']] | ['VP'] | False |
['VP', ['V']] | ['VP', 'V'] | False |
SOLUTION
SHARE
If you find this useful, please share with your friends and Community.
CODE TOGETHER..GROW TOGETHER.
CODE TOGETHER..GROW TOGETHER.
Newer Posts
Newer Posts
Older Posts
Older Posts
Comments