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?
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?
(```) 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 ```
Many thanks!
Join our real-time social learning platform and learn together with your friends!