Problem with Lists in Python - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Problem with Lists in Python (/thread-12458.html) |
Problem with Lists in Python - DEAD_BOT - Aug-25-2018 Thanks for answering my question in advanced... Sorry If I sound Stupid. I popped an element from the middle of a list in python how do I re-insert it? To be specific, I was learning to use Lists in Python. I popped an element from the middle of a list, but I am unable to figure out that how to re-insert or insert another element in between my list? for example, I did new_list.pop(0)and it popped the zeroth element but then I tried to re-insert the same element and I was unsuccessful, I don't know if there are any attributes that I don't know yet that does this but what if I popped an element from the middle of a List and I wanted to re-insert it to the same place, or If I wanted to add another element in the middle of my list, How exactly would I do that? I am posting an image to clarify that... Link -->http://prntscr.com/kmt8z9 RE: Problem with Lists in Python - buran - Aug-25-2018 >>> lst=[1, 2, 4] >>> lst.insert(2, 3) # insert 3 at index 2. indexing is 0-based >>> lst [1, 2, 3, 4] >>> RE: Problem with Lists in Python - DEAD_BOT - Aug-26-2018 Thanks Man, for the answer... now I understand it :) |