Memory limit exceeded??? | Sololearn: Learn to code for FREE!

0

Memory limit exceeded???

aList = [123, 'xyz', 'zara', 'abc']; for x in aList: aList.append(x) print (x) print (aList) Above is the code. Why it shows me memory limit exceeded???

10/31/2018 10:41:34 PM

livperis

7 Answers

New Answer

+2

I'm no Python expert, but livperis, if you just wanna copy aList to itself _once_ then: aList.append(aList) should work as Python is very abstract. I believe this may work too, even: aList = aList + aList If you _need_ to copy _element-by-element_, I guess: bList = [] bList.append(aList); for ii in aList: bList.append(ii) Note: Python provides iterators and other stuff, iirc, so there's a way to do it like a boss probably, I just don't recall Python enough to recall it. * Honestly, I barely recall _any_ Python.

+1

Because it infinitely keeps adding to the list. Each element found, another is appended as it iterates through aList. Thus aList keeps growing, it keeps iterating, it keeps growing... forever or until terminated. What are you tryna do?

+1

You appear to be modifying the list over which you're iterating. At what point does it stop?

+1

Thank you you were very helpful to me.

0

Thank you very much.

0

I am trying to copy the items of the aList 123, 'xyz', 'zara', 'abc' once again in aList.

0

Cool, NP :)