This is because an iterator is returned in the Python 3.x map() function, which uses the list link passed to it as the second parameter. Since you are repeating a map iterator, you are also expanding the list, and it goes on forever, so you either get a MemoryError or end with an infinite loop.
An example to show this behavior is
>>> m = map(lambda x: a.extend(x), a) >>> m <map object at 0x021E0E70> >>> for i,x in enumerate(m): ... print("Hello") ... Hello Hello .... # lots of Hello Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 1, in <lambda> MemoryError
So, when you do - a.extend(map(lambda x: 'b' + x, a)) . You do something similar -
a = ['a'] for x in a: a.extend('b'+x)
If you try the code above, you still get a MemoryError or an infinite loop.
When you do that -
a.extend(list(map(lambda x: 'b' + x, a)))
You use an iterator, converting it to a list, before expanding the list of a , therefore, it does not end with an infinite loop. In this case, you are doing something similar to -
a = ['a'] templist = [] for x in a: templist.extend('b' + x) a.extend(templist)
That is why you are not getting an error. Please note that the above code may not be the same as python internally runs map , its just something similar.