# Final Exam: Question 8: same structure

 0 Sir, you have said in the question that "if lists contain the same elements in the same structure ...", but sample outputs show that the two given input lists p and q need not contain "same elements", but same number of elements. Ex: 1st sample output (i agree with all other statements you have specified). This is what i have interpreted from the question. correct me if i am wrong sir. asked 02 Apr '12, 09:31 niranjan-1 4●1●2●2 accept rate: 0%

 0 Given the examples given in the homework description, I would agree with your interpretation. [1, 2] has not the same structure as [1,2,3] or ['ab'] or [1, [2]] but has the same structure as ['a', 'b']. print same_structure([1, [2, [3, [4, 5]]]], ['a', ['b', ['c', ['d', 'e']]]]) >>> True print same_structure([1, [2, [3, [4, 5]]]], ['a', ['b', ['c', ['de']]]]) >>> False  answered 02 Apr '12, 09:37 Elise 3.7k●5●16●56
 0 Try to create the tree for both the inputs - they should match in the shape but the leaf values may be different. So, they have same structure but the values may not be the same. answered 02 Apr '12, 09:59 rakesh kumar 1.5k●5●14●44
 0 In the case: print same_structure([1, [2, [3, [4, 5]]]], ['a', ['b', ['c', ['d', 'exam']]]])  Have they the same structure???? answered 02 Apr '12, 15:05 Pedro Montero-4 40●1●4 @Pedro Yes, they do. (02 Apr '12, 15:11) fnenu-1 ♦♦ Yes they have the same structure. (03 Apr '12, 08:45) Nilesh K Mol...
 -1 I have a deliciously clever way to do this, but as I'm not allowed to tell, I won't! Mwahahaha! answered 02 Apr '12, 15:17 Charles Lin 9.2k●42●94●135 how does one evaluate [] element in the list to compare structure? For example if value of a is integer and value of b is [] structurally they are not the same. In this case how does evaluate b. I tried a == [] or b == []. For some reason it doesn't work. (06 Apr '12, 01:36) Parikh Jagdi...
Question text:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "Title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported

×15,218
×664
×637
×369
×19
×9