1 / 6

Dictionaries

Dictionaries. Dictionaries. Allow you to retrieve data using a key (instead of an index). Classic dictionary: Search/retrieve using a word Get the definition of the word Python dictionary: Retrieve using a key Get data associated with the key. Creating a dictionary.

walda
Download Presentation

Dictionaries

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. Dictionaries

  2. Dictionaries • Allow you to retrieve data using a key (instead of an index). • Classic dictionary: • Search/retrieve using a word • Get the definition of the word • Python dictionary: • Retrieve using a key • Get data associated with the key

  3. Creating a dictionary • students = {‘Joe’:[CPSC231,MATH271],’Katie:[PSYC205,ENGL201]} • dict = {}

  4. Adding and Retrieving Values • students[‘Bob’] = [CPSC231,PHIL279] • x = students[‘Joe’]

  5. Keys • Type must be immutable • Strings • Integers • Tuples • etc • Keys in a dictionary must be unique

  6. Methods • clear • get • items • keys • values

More Related