CS61A Lecture 11: Sequences

3 Pages
Unlock Document

Computer Science
De Nero

Sequence Abstraction No one sequence class or abstract data type Collection of behaviors: Length. Finite length Element selection. A sequence has element corresponding to non-negative integer index less than length, start at 0 for first element Built-in syntax for sequence Tuple is a kind of sequence, tuple can be more than 2 elements odds = (41, 43, 47, 49) len(odds) odds[1] odds[0] * odds[3] + len(odds) odds[odds[3]-odds[2]] Box and Pointer Notation The Closure Property of Data Types A method for combining data values satisfies the closure property if: Result of combination can be combined using same method Closure is key to power in any means of combination because allow create hierarchy structure Hierarchal structure made of parts, which are made of parts, etc. Tuples can contain tuples as elements Recursive Lists Implement recursive lists as pairs, Use two-element tuple A recursive list is a pair: First element of pair is first element in list Second element of pair is rest of the list empty_rlist = None def rlist(first, rest): """Return a recursive list from its first element and the rest.""" return (first, rest) def first(s): """Return the first element of a recurs
More Less

Related notes for COMPSCI 61A

Log In


Join OneClass

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

Sign up

Join to view


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.