The Noobs of Python: Ep.2.1 - List : Slice, Loops and more [Updated]

Continuing with the update to this thread here are some methods to help you along the way. If you have questions on the implementation of these methods, please comment below !

>>> A.insert(3, ['Wasp', 'Nadia Pym'])
>>> A
['Avengers', ['Tony Stark', 'Ironman'], ['Steve Rodgers', 'Captain America'], 
['Wasp', 'Nadia Pym'], ['Thor', 'Eric Masterson'], ['Great Lakes Avengers', 
['Mr.Immortal', 'Craig Hollis'], ['Big Bertha', 'Ashley Crawford'], 
['Doorman', 'Demarr Davis'], ['Flatman', 'Matt']]]

Here we used the .insert() to … you guessed it, insert A.insert(3, ['Wasp', 'Nadia Pym'])
Q: How does this differ from .append()
A: Well with .insert() you need to specify where to insert your object which can come in handy often. so in the example above, the .insert() is as follows :
.insert( index, object) where as append will just append to the end of the list.

Q: So what are other methods useful to list?
A: .remove() is another useful method to utilize in a List, Here is an example:

>>> A
['Avengers', ['Tony Stark', 'Ironman'], ['Steve Rodgers', 'Captain America'], 
['Wasp', 'Nadia Pym'], ['Thor', 'Eric Masterson'], ['Great Lakes Avengers', 
['Mr.Immortal', 'Craig Hollis'], ['Big Bertha', 'Ashley Crawford'], 
['Doorman', 'Demarr Davis'], ['Flatman', 'Matt']]]
>>>
>>>
>>> A.remove(A[4])
>>> A
['Avengers', ['Tony Stark', 'Ironman'], ['Steve Rodgers', 'Captain America'], 
['Wasp', 'Nadia Pym'], ['Great Lakes Avengers', ['Mr.Immortal', 'Craig Hollis'], 
['Big Bertha', 'Ashley Crawford'], ['Doorman', 'Demarr Davis'], ['Flatman', 'Matt']]]
>>> 

As you can see in the example above, we used .remove() to remove the 4th object in the list which is ['Thor', 'Eric Masterson'] if you compare the 2. I used the index number which is 4 for it, but you can used the list object as well.

Also akin to .remove() is another method called .pop() which will remove any give item in the List and return it. Here is an example below:

>>> A.pop(2)
['Steve Rodgers', 'Captain America']
>>> A
['Avengers', ['Tony Stark', 'Ironman'], ['Wasp', 'Nadia Pym'], 
['Great Lakes Avengers', ['Mr.Immortal', 'Craig Hollis'], 
['Big Bertha', 'Ashley Crawford'], ['Doorman', 'Demarr Davis'], 
['Flatman', 'Matt']]]
>>> 

As you can see, we .pop(2) which was ['Steve Rodgers', 'Captain America'] as shown from idle3. If you do not specify any number to pop, it will default to the last in the List.

And of course we can clear all of our objects in the lList by using .clear() as seen below:

>>> A.clear()
>>> A
[]
>>> 

Now your A list is empty for you to try some other devious things to do with List ! Lol

There are several other methods that can be used with List like : .copy() | .reverse() | .sort() | .count() .extend()
If you have any questions just reply in the comments section below !

Code_One_Code_Warriors !!!