Class Notes (839,087)
Canada (511,185)
CSC108H1 (113)
Lecture

november 14 notes

1 Page
70 Views

Department
Computer Science
Course Code
CSC108H1
Professor
Michelle Craig

This preview shows half of the first page. Sign up to view the full page of the document.
Description
 Function: function.py 1. def insert_after(L, n1, n2): 2. '''L is a list of ints; n1 and n2 are ints. After each occurrence of n1 3. in L, insert n2.''' 4. 5. i = 0 6. while i < len(L): 7. if L[i] == n1: 8. #L = L[:i+1] + [n2] + L[i+1:] 9. L.insert(i+1, n2) 10. i += 1 # skip over the just inserted element 11. i += 1  Testing function: 1. import nose 2. from insert_after import insert_after 3. 4. def test_empty(): 5. L = [] 6. insert_after(L, 1, 1) 7. assert L == [] 8. 9. def test_one_not_n1(): 10. L = [0] 11. insert_after(L, 4, 99) 12. assert L == [0] 13. 14. def test_one_n1(): 15. L = [0] 16. insert_after(L, 0, 99) 17. assert L == [0, 99] , 'L is '+str(L) 18. 19. def test_longer_no_n1(): 20. L = [0, 1, 2, 3, 4, 5] 21. insert_after(L, 14, 99) 22. assert L == [0, 1, 2, 3, 4, 5] 23. 24. def test_
More Less
Unlock Document

Only half of the first page are available for preview. Some parts have been intentionally blurred.

Unlock Document
You're Reading a Preview

Unlock to view full version

Unlock Document

Log In


OR

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.


Submit