2014-03-25 + HW

posted Mar 25, 2014, 5:13 AM by Samuel Konstantinovich   [ updated Mar 25, 2014, 5:13 AM ]
Goal: Practice with lists

Note: Test Thursday.

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: use index to write a very simple find method for a list:

def find(listName, value):
     

Such that 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

Codingbat.com :
LIST-1: (warmup)
  sum3  rotate_left3   reverse3
LIST-2: (real problems)
  Complete all 6 problems by Wednesday evening. You have today in class + 2 evenings of homework time. You can work with a neighbor today in class, and of course use piazza. Problems like these will be on the test

Comments