Python Data Structures

Slides:



Advertisements
Similar presentations
Chapter 6 Lists and Dictionaries CSC1310 Fall 2009.
Advertisements

Lecture 12 – ADTs and Stacks.  Modularity  Divide the program into smaller parts  Advantages  Keeps the complexity managable  Isolates errors (parts.
Queues CS-240 & CS-341 Dick Steflik. Queues First In, First Out operation - FIFO As items are added they are chronologically ordered, items are removed.
CS 206 Introduction to Computer Science II 10 / 26 / 2009 Instructor: Michael Eckmann.
Queues CS-240 & CS-341 Dick Steflik. Queues First In, First Out operation - FIFO As items are added they are chronologically ordered, items are removed.
Lists, Stacks, Queues Svetlin Nakov Telerik Corporation
Data Structures Akshay Singh.  Lists in python can contain any data type  Declaring a list:  a = [‘random’,’variable’, 1, 2]
Data Structures in Python By: Christopher Todd. Lists in Python A list is a group of comma-separated values between square brackets. A list is a group.
CS 46B: Introduction to Data Structures July 9 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak
C++ STL CSCI 3110.
COMP 103 Linked Lists. 2 RECAP-TODAY RECAP  Linked Structures: LinkedNode  Iterating and printing Linked Nodes  Inserting and removing Linked Nodes.
Built-in Data Structures in Python An Introduction.
Daniel Jung. Types of Data Structures  Lists Stacks Queues  Tuples  Sets  Dictionaries.
Introduction to the Standard Template Library (STL) A container class holds a number of similar objects. Examples: –Vector –List –Stack –Queue –Set –Map.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 9 Dictionaries and Sets.
1 Joe Meehean.  List of names  Set of names  Map names as keys phone #’s as values Phil Bill Will Phil Bill Will Phil Bill Will Phil: Bill:
CS105 STRING LIST TUPLE DICTIONARY. Characteristics of Sequence What is sequence data type? It stores several objects Each object has an order Each object.
Collections Data structures in Java. OBJECTIVE “ WHEN TO USE WHICH DATA STRUCTURE ” D e b u g.
Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record.
Tuples Chapter 10 Python for Informatics: Exploring Information
14. DICTIONARIES AND SETS Rocky K. C. Chang 17 November 2014 (Based on from Charles Dierbach, Introduction to Computer Science Using Python and Punch and.
LECTURE 3 Python Basics Part 2. FUNCTIONAL PROGRAMMING TOOLS Last time, we covered function concepts in depth. We also mentioned that Python allows for.
C++ Review STL CONTAINERS.
Stacks and Queues CMSC 201. Stacks and Queues Sometimes, when we use a data-structure in a very specific way, we have a special name for it. This is to.
Python Data Structures By Greg Felber. Lists An ordered group of items Does not need to be the same type – Could put numbers, strings or donkeys in the.
CS2910 Week 6, Lab Today Dictionaries in Python SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1.
Collections ABCD ABCD Head Node Tail Node array doubly linked list Traditional Arrays and linked list: Below is memory representation of traditional.
Advanced Python Idioms
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
Lecture 3 Python Basics Part 2.
Topics Dictionaries Sets Serializing Objects. Topics Dictionaries Sets Serializing Objects.
CSCI 104 Abstract Data Types
CMSC201 Computer Science I for Majors Lecture 21 – Dictionaries
Containers and Lists CIS 40 – Introduction to Programming in Python
Data Structures: Lists
Chapter 2 (16M) Sorting and Searching
JAVA COLLECTIONS LIBRARY
Standard Template Library (STL)
Dictionaries, File operations
Lecture 10 Data Collections
Road Map CS Concepts Data Structures Java Language Java Collections
structures and their relationships." - Linus Torvalds
LING 388: Computers and Language
structures and their relationships." - Linus Torvalds
Bryan Burlingame Halloween 2018
Data Structures – 1D Lists
CS 1111 Introduction to Programming Fall 2018
Python for Informatics: Exploring Information
Chapter 5: Lists and Dictionaries
Stack A data structure in which elements are inserted and removed only at one end (called the top). Enforces Last-In-First-Out (LIFO) Uses of Stacks Evaluating.
Topics Dictionaries Sets Serializing Objects. Topics Dictionaries Sets Serializing Objects.
Dictionaries Dictionary: object that stores a collection of data
Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract, Computer,
6. Dictionaries and sets Rocky K. C. Chang 18 October 2018
CS 1111 Introduction to Programming Spring 2019
15-110: Principles of Computing
Advanced Python Idioms
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Advanced Python Idioms
Fundaments of Game Design
Bryan Burlingame Halloween 2018
CSE 231 Lab 8.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
structures and their relationships." - Linus Torvalds
Sample lecture slides.
COMPUTER SCIENCE PRESENTATION.
Dictionary.
Python List.
© Sangeeta M Chauhan, Gwalior
Python - Tuples.
Presentation transcript:

Python Data Structures CS 265 Seth Simpson

Lists Creating Lists List methods exampleList = [1,3,5,7,9] Append(element) – appends element to end Extend(list) – extends the list with another list Insert(position, element) – insert element at the given position Remove(element) – removes the first occurrence of the element

Lists (Cont) More List methods Pop(index) – Remove and return the element at index (last element by default) Index(element) – returns index of the first occurrence of element Count(element) – returns the number of times element appears in the list Sort() – sorts the list Reverse() – reverses the list

Example of List Methods

Lists as Stacks Last in – First out List pop function enables us to treat lists as stacks.

Lists as Queues First in – first out Popping end elements of a list is fast because the elements don’t need to be rearranged Popping from the front of a list is slow because the list needs to be rearranged

List Filtering Filter(function name, list) Returns a sequence of items for which function(item) is true. Example:

List Mapping Map(function name, list) Calls the function for each value in the list and outputs the results as list Example:

List Reducing Reduce(function name, list) Returns a single value by computing the function value on the first two elements, then the result of that with the next element and so on.

Sets Unordered collection with no duplicates

Sets (Cont)

Dictionaries Unsorted set of Key : Value pairs

Dictionaries (Cont) Can also call the dict() constructor to create a dictionary. Printing out Dictionaries