Why does my code produce TypeError: 'NoneType' object is not iterable
python, python-3.x
Solution
`return minElm.extend( merge(s1[:], s2[:] ))` returns None, specifically because the `list.extend` method returns None. Instead, do one of the following:
minElm.extend( merge(s1[:], s2[:] ))
return minElm
or
return minElm + merge(s1[:], s2[:] )
Problem
I know this error has been asked several times, but I am stuck with my code for why it keep returning TypeError ``` def merge( s1, s2): if len(s1) == 0: return s2[:] if len(s2) == 0: return s1[:] minElm = [] if s1[0] <= s2[0]: minElm.append( s1.pop(0) ) else: minElm.append( s2.pop(0) ) return minElm.extend( merge(s1[:], s2[:] )) list1 = [1,3,5,7,9] list2 = [2,4,6,8] merged = merge( list1[:], list2[:] ) print(merged) ``` Basically, I want to merge two already sorted lists (ASC) into a single sorted list (ASC) using recursive method. I'm positive that my logic is correct, I just cannot get why am I getting `TypeError: 'NoneType' object is not iterable` Why am I getting the `TypeError`?