Python: More List Functions
Since sequences have so many uses and functions, in this lesson we are simply going over some more sequence functions.
"len" is the first function we will learn about today.
It simply gets the length of the function, for example if we had a sequence with 6 elements the len would be 6:
SequenceOne = [55, 192, 856, 19, 3] len(SequenceOne)
The above would output 5, as there is 5 elements.
We also have "min" and "max" functions to find the smallest, and biggest numbers in the sequence - for example:
max(SequenceOne) min(SequenceOne)
Another extremely useful thing you can do with sequences, is set certain elements in the sequence.
For example if we created a new sequence called SequenceTwo (it would have worked fine with SequenceOne, but I just created a new sequence because I wanted to):
SequenceTwo = list('Joe')
This simply creates a list from the string.
Now lets replace the last two letters (using their assigned numbers):
SequenceTwo[1] = 'e' SequenceTwo[2] = 'w'
This simply changed our list ['J', 'o', 'e'] to ['J', 'e', 'w'].
We can also do this with lists of numbers.
We can also delete an element in the array using it's number and the "del" keyword:
del SequenceTwo[2] SequenceTwo[0] = 'H' SequenceTwo[1] = 'i'
Our list is now ['H', 'i'].
Back to Python

