{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

slides9-4up[1] - Lists and Tuples and Sets(Oh My From Lists...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Compsci 06/101, Spring 2011 9.1 Lists and Tuples and Sets (Oh My) Lists are versatile, useful, wonderful, mutable Given list, cannot stop client code/user from changing it Sometimes mutable data is NOT a good thing Strings are immutable, can be very efficient at large scales Lists are mutable, cannot offer same efficiencies Tuples are similar to lists, but immutable Cannot add a list to a set, can add a tuple to a set We will see later: very, very useful in dictionaries Useful in other contexts as well: immutable (poker code) See code examples Compsci 06/101, Spring 2011 9.2 From Lists to Tuples lists, lints, lines, fines, fixes, fixed lists, fists, fiats, feats, seats, stats, stars, stark, stack, stuck def get_roll(): return [random.randint(1,6),random.randint(1,6)] def track(n): store = set() for x in range(n): store.add(get_roll()) return len(store ) store.add(get_roll()) TypeError: unhashable type: 'list' Compsci 06/101, Spring 2011 9.3 Tuomas Sandholm, CMU Professor IJCAI Computers and Thought 2003
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Ask a homework question - tutors are online