Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 15 Online
OpenStudy (kizolk):

I've taken the Practice Quiz 1 (which doesn't come with solutions), and it'd be great if someone could chekc my answer to one of the questions. 7) Consider the following code: def f(L): result = [] for e in L: if type(e) != list: result.append(e) else: return f(e) return result 7.2. What does print f([1, [[2, 'a'], ['a','b']], (3, 4)]) print? My answer is: [2, 'a']. Is that correct? I get a little confused about recursion and how return statements behave. Also, how do you type code here?

OpenStudy (kizolk):

Have I just done what I think I did? *facepalm* I could have...checked it on hm, Python and stuff ^^;; Sorry guys! My other question still holds, though: how do you write code here?

OpenStudy (turingtest):

(```) code (```) remove the parentheses: ``` def f(L): result = [] for e in L: if type(e) != list: result.append(e) else: return f(e) return result ```

OpenStudy (kizolk):

Many thanks!

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!