1 / 6

Collections

Collections. Michael Ernst UW CSE 140. Count the words in a document. Assume you start with a list of words:

wattan
Download Presentation

Collections

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Collections Michael Ernst UW CSE 140

  2. Count the words in a document Assume you start with a list of words: "to be or not to be that is the questionwhether tis nobler in the mind to sufferthe slings and arrows of outrageous fortuneor to take arms against a sea of troublesand by opposing end them to die to sleepno more".split()

  3. Count the occurrences of each word(make a histogram) Most common words on Twitter

  4. Count the number of unique words

  5. A collection groups similar things • List: ordered • Set: unordered, no duplicates • Tuple: unmodifiable list • Dictionary: maps from values to values Example: word → definition

  6. Data Structures • A data structure is way of organizing data • Each data structure makes certain operations convenient or efficient • Each data structure makes certain operations inconvenient or inefficient • Example: What operations are efficient with: • a file cabinet sorted by date? • a shoe box?

More Related