<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Lists
<img src="../images/python-logo.png">
Lists are sequences that hold heterogenous data types that are separated by commas between two square brackets. Lists have zero-based indexing, which means that the first element in the list has an index on '0', the second element has an index of '1', and so on. The last element of the list has an index of 'N-1' where N is the length of the list.
Step1:  Define a list
Step2:  Accesing elements of a list
<ASSISTANT_TASK:>
Python Code:
# import thr random numbers module. More on modules in a future notebook
import random
Explanation: Lists
<img src="../images/python-logo.png">
Lists are sequences that hold heterogenous data types that are separated by commas between two square brackets. Lists have zero-based indexing, which means that the first element in the list has an index on '0', the second element has an index of '1', and so on. The last element of the list has an index of 'N-1' where N is the length of the list.
End of explanation
# empty list
a = list()
# or
a = []
# define a list 
a = [1,2,3,4,2,2]
print a
# list of numbers from 0 to 9
a = range(10)
a
Explanation: Define a list
End of explanation
# Python is zer-bases indexing
a[0]
# Get the last element
a[-1]
# Get the next to the last element
a[-2]
a[:]
# Slice the list
a[0:6] # elements with indecies 0, 1, 2, & 3
a = [1,2,2,3,4,4,4,6,7,2,2,2]
# Get the number of occurences of the element 2
a.count(2)
# the original list
a
# remove the element at with index 2 and return that value
a.pop(2)
# a is now modified
a
# delete without return
del a[1] # delete element at index 1
# print a
a
2 not in a
5 in a
# list can contain any type of Python objects, including lists
f = [1, '2', 'a string', [1, ('3', 2)], {'a':1, 'b':2}]
# get element @ index 2
f[2]
# change it
f[2] = 3
f
# length of the list
len(f)
import random
# list comprehension
a = [int(100*random.random()) for i in xrange(150)]
print a
# the same as
a = []
for i in range(150):
    a.append(int(100*random.random()))
    
    
# get the max and min of a numeric list
max(a), min(a)
# make a tuple into a list
x = (1,2,3,4,5)
list(x)
# add object to the end of the list
x = [1,2,3]
x.append(4)
print x
x.append([6,7,8])
print x
# Appends the contents of seq to list
x.extend([9,10,11,12,[13,14,15]])
print x
x.extend([1,2,3])
x
a = [1,2,3]
b = [4,5,6]
c = a+b
c
# Returns count of how many times obj occurs in list
x.count(3)
# Returns the lowest index in list that obj appears
x.index(10)
# Inserts object obj into list at offset index
print x[3]
x.insert(3, ['a','b','c'])
print x
# Removes and returns last object or obj from list
x.pop()
print x
print x[3]
x.pop(3)
print x
# Removes the first occurrence of obj from list
x = [1,2,2,3,4,5,2,3,4,6,3,4,5,6,2]
x.remove(2)
print x
# Reverses objects of list in place
x.reverse()
print x
# Sort x in place
x.sort()
print x
# duplicate a list
a = [1,2,3]
b = a*5
b
import random
[random.random() for _ in range(0, 10)]
x = [random.randint(0,1000) for _ in range(10)]
print x
random.choice(x)
print range(10)
print range(0,10)
print range(5,16)
print range(-6, 7, 2)
M=[[1,2,3],
   [4,5,6],
   [7,8,9]]
print M
# put the 2nd column of M in a list
column = []
for row in M:
    column.append(row[1])
print column
# list comprehension - another way of extracting the 2nd column of M
column = [row[1] for row in M]
print column
# compute the transpose of the matrix M
[[row[i] for row in M] for i in range(3)]
# get the diagonal elements of M
diag = [M[i][i] for i in [0, 1, 2]]
print diag
# build a list with another list as elements
[[x ** 2, x ** 3] for x in range(4)]
# build a list with an if statement
[[x, x/2, x*2] for x in range(-6, 7, 2) if x > 0]
# does the same thing as above but more 
big_list = []
for x in range(-6,7,2):
    if x > 0:
        big_list.append([x, x/2, x*2])
print big_list
# does the same as above but lots of code
big_list = []
for x in range(-6,7,2):
    lil_list = []
    if x > 0:
        lil_list.append(x)
        lil_list.append(x/2)
        lil_list.append(x*2)
        big_list.append(lil_list)
print big_list
L = ["Good", # clint
     "Bad",  # 
     "Ugly"]   
print L
Explanation: Accesing elements of a list
End of explanation
<END_TASK>