introduction to computer programming data structures csci
play

{} Introduction to Computer Programming Data Structures CSCI-UA 2 - PowerPoint PPT Presentation

Introduction to Computer Programming Data Structures CSCI-UA 2 Dictionaries {} Introduction to Computer Programming Data Structures CSCI-UA 2 Dictionaries {key: value} Dictionaries {} A dictionary is a data structure for storing pairs


  1. Introduction to Computer Programming Data Structures CSCI-UA 2 Dictionaries {}

  2. Introduction to Computer Programming Data Structures CSCI-UA 2 Dictionaries {key: value} Dictionaries {} A dictionary is a data structure for storing pairs of values Values can be accessed by their keys Like lists, dictionaries are mutable Keys are unique and cannot be repeated within a dictionary Keys must be immutable and cannot be a list or dictionary Values are, however, mutable

  3. Introduction to Computer Programming Data Structures CSCI-UA 2 Dictionaries dict.items() Dictionaries dict.keys() Methods dict.values() dict.get() dict.pop() dict.popitem() dict.clear() dict.copy() dict.fromkeys() dict.update()

  4. 
 
 
 
 
 
 Introduction to Computer Programming Data Structures CSCI-UA 2 Dictionaries Order Lists vs. Dictionaries • Lists are ordered • Dictionaries are unordered Access • Lists require a numeric index to access individual items • Dictionary values are accessed by their unique key General Guideline • If order matters, use a list • If you need to access values with a unique key, use a dictionary

  5. Introduction to Computer Programming Data Structures CSCI-UA 2 Tuples (1, 2.0, 'three') Tuples () A tuple is an immutable sequence of 0 or more values Enclosed in round brackets, items separated by a comma Tuples with a single item must be followed by a comma: (x,) Once created, it cannot be changed, which can help prevent errors Use indexing and slicing to access individual elements

  6. Introduction to Computer Programming Data Structures CSCI-UA 2 Sets A set is a collection of 0 or more items Sets with no duplicates set() A good way to remove duplicates from a sequence Two categories: mutable sets and immutable frozensets

  7. Introduction to Computer Programming Data Structures CSCI-UA 2 Dictionaries

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend