1 / 6

Dictionaries

Discover the fundamentals of Python dictionaries, a powerful data structure that allows data retrieval using keys instead of indices. Learn how to create dictionaries, such as mapping students to their courses, and understand key characteristics like immutability and uniqueness of keys. Explore important dictionary methods including clear(), get(), items(), keys(), and values(), which enhance data management in Python programming. This guide is tailored for beginners and will provide you with essential knowledge for working with dictionaries efficiently.

walda
Télécharger la présentation

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