Skip to content

Instantly share code, notes, and snippets.

@venkatsgithub1
Created April 15, 2017 16:53
Show Gist options
  • Save venkatsgithub1/78ea7134a640f9249529fdda1f31151b to your computer and use it in GitHub Desktop.
Save venkatsgithub1/78ea7134a640f9249529fdda1f31151b to your computer and use it in GitHub Desktop.
Python | Removal of data from a list using pop method.
#Usage of pop method to remove elements from list.
def print_popped_element (element):
print ("%s is popped out from list" %element)
list_of_items=["Watch", "Headphones", "Mobile Phone", "Laptop"]
"""
********************************************
Pop out from list using index.
********************************************
Index 2 is provided to pop, hence
element at index 2 shall be removed
from the list, in this case "Headphones".
list_of_items becomes
["Watch", "Headphones", "Laptop"]
"""
print_popped_element(list_of_items.pop(2))
"""
********************************************
Pop out from list w/o index.
********************************************
Here no index indicates that the last
item in the list shall be removed.
list_of_items becomes
["Watch", "Headphones"]
"""
print_popped_element(list_of_items.pop())
print ("%s are left out in list_of_items" %list_of_items)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment