Lecture 29 + HW:

posted Mar 14, 2013, 5:29 AM by Samuel Konstantinovich   [ updated Mar 15, 2013, 5:43 AM ]
Goal: Practice with lists

List don't have a find method. There is another method that is useful:
listName.index(value)   will act just like find when the value is in the list, but will give an error if the value is not found in a list. 
>>>a=[3,9,4]
>>>print a.index(3)
0
>>>print a.index(9)
1
>>>print a.index(2)
VALUE ERROR: NOT IN LIST

DO NOW: On paper write a find function for lists. You can use built in list methods to help you!

def find(listName, value):
     ???

You can then use find as follows:
>>> print find(x,2)
1
>>> print find(x,6)
-1
>>> print find(x,'1')
-1
>>> print find(x,4)
3


CLASSWORK/HOMEWORK

(Period 7 and 10 you have a guest lecture today! Instead of class time to work on these problems you must complete them at home. This is the price of a guest lecturer, but you have plenty of time to do it)

Codingbat.com : (with your partner next to you)
LIST-1:
  Optional easy problems. Do at least 3 of these. You should definitely do same_first_last as it requires you to read the question VERY carefully to complete and many people had trouble with it. Incidentally the site has a typo and says that nums.length is the length, when in fact python requires you to use the len function: len(nums)
LIST-2:
  Complete all 6 problems by Monday, you have today and tomorrow in class)



Comments