Daniel Jung. Types of Data Structures  Lists Stacks Queues  Tuples  Sets  Dictionaries.

Slides:



Advertisements
Similar presentations
Stacks, Queues, and Linked Lists
Advertisements

Linear ADT Done By : Kishan Gopaul.
Chapter 6 Lists and Dictionaries CSC1310 Fall 2009.
Stacks, Queues, and Deques. 2 A stack is a last in, first out (LIFO) data structure Items are removed from a stack in the reverse order from the way they.
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
Guide to Programming with Python
1 Sequences A sequence is a list of elements Lists and tuples – Lists mutable – Tuples immutable Sequence elements can be indexed with subscripts – First.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L12 (Chapter 20) Lists, Stacks,
Data Structures Akshay Singh.  Lists in python can contain any data type  Declaring a list:  a = [‘random’,’variable’, 1, 2]
Python Data Structures
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.
Beyond Lists: Other Data Structures CS303E: Elements of Computers and Programming.
Hossain Shahriar Announcement and reminder! Tentative date for final exam need to be fixed! Topics to be covered in this lecture(s)
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 20 Lists, Stacks,
Collecting Things Together - Lists 1. We’ve seen that Python can store things in memory and retrieve, using names. Sometime we want to store a bunch of.
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ LinkedList ◦ Set ◦ Map 2.
1 Chapter 17 Object-Oriented Data Structures. 2 Objectives F To describe what a data structure is (§17.1). F To explain the limitations of arrays (§17.1).
Built-in Data Structures in Python An Introduction.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 8 Lists and Tuples.
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.
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.
Lists CS303E: Elements of Computers and Programming.
Lecture 7 : Intro. to STL (Standard Template Library)
Tuples Chapter 10 Python for Informatics: Exploring Information
Python Data Structures CMSC 201. Built in Types Today we will be talking about some other built in types in python! Tuples Sets Dictionaries.
Collections Michael Ernst CSE 190p University of Washington.
Data Collections CS 127. Lists Lists are ordered sequences of items All programming languages provide a sequence structure similar to a Python list; in.
Guide to Programming with Python Chapter Five Lists and dictionaries (data structure); The Hangman Game.
LECTURE 3 Python Basics Part 2. FUNCTIONAL PROGRAMMING TOOLS Last time, we covered function concepts in depth. We also mentioned that Python allows for.
LISTS and TUPLES. Topics Sequences Introduction to Lists List Slicing Finding Items in Lists with the in Operator List Methods and Useful Built-in Functions.
CSCI 383 Object-Oriented Programming & Design Lecture 25 Martin van Bommel.
COSC 1306—COMPUTER SCIENCE AND PROGRAMMING PYTHON TUPLES, SETS AND DICTIONARIES Jehan-François Pâris
Lists Michael Ernst CSE 140 University of Washington.
Introduction to Python Aug 22, 2013 Hee-gook Jun.
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.
Stacks. What is a Stack? A stack is a type of data structure (a way of organizing and sorting data so that it can be used efficiently). To be specific,
Python Lists and Sequences Peter Wad Sackett. 2DTU Systems Biology, Technical University of Denmark List properties What are lists? A list is a mutable.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
Map, List, Stack, Queue, Set Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where otherwise noted,
String and Lists Dr. José M. Reyes Álamo.
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.
Containers and Lists CIS 40 – Introduction to Programming in Python
Data Structures: Lists
Lecture 10 Data Collections
Chapter 17 Object-Oriented Data Structures
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Guide to Programming with Python
Python Data Structures
String and Lists Dr. José M. Reyes Álamo.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Topics Sequences Introduction to Lists List Slicing
Mutable Data (define mylist (list 1 2 3)) (bind ((new (list 4)))
Topics Dictionaries Sets Serializing Objects. Topics Dictionaries Sets Serializing Objects.
Dictionaries Dictionary: object that stores a collection of data
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Bryan Burlingame Halloween 2018
Topics Sequences Introduction to Lists List Slicing
Stacks, Queues, and Deques
Intro to Computer Science CS1510 Dr. Sarah Diesburg
COMPUTER SCIENCE PRESENTATION.
Dictionary.
Python List.
Introduction to Computer Science
Ruth Anderson UW CSE 160 Winter 2016
Presentation transcript:

Daniel Jung

Types of Data Structures  Lists Stacks Queues  Tuples  Sets  Dictionaries

Methods of List  list.append(item) Adds an item to the end of the list.  list.extend(List) Extends the list by appending all the items in the given list.  list.insert(i, item) Inserts an item at a given position. The argument i is the index of the element before which to insert.  list.remove(x) Removes the first item from the list whose value is x.

Methods of List (cont.)  list.pop(item) or list.pop() Removes the item at the given position in the list, and returns it. Removes and returns the last item in the list if no index is specified.  list.index(x) Returns the index in the list of the first item whose value is x.  list.count(x) Returns the number of times the value x appears in the list.  list.sort() Sorts the items of the list in order.  list.reverse() Reverses the order of elements of the list.

List as Stack  To add an item to the top of the stack, use the append(x).  To retrieve an item from the top of the stack, use pop().  Example: myStack = [1, 2, 3] myStack.append(4) Result: [1, 2, 3, 4] myStack.pop() Result: [1, 2, 3]

List as Queue  Possible, but not very efficient.  To implement a queue, type “from collections import deque”  Example: from collections import deque myQueue = deque([“Duke”, “Nukem”, “Is”]) myQueue.append(“Coming”) Result: [“Duke”, “Nukem”, “Is”, “Coming”] myQueue.popleft() Result: [“Nukem”, “Is”, “Coming”]

Useful Built-in Functions for Lists  filter(function, sequence) Returns a sequence consisting of those items from the sequence for which function(item) is true.  map(function, sequence) Calls function(item) for each of the items in the sequence and returns a list of the return values.  reduce(function, sequence) Returns a value constructed by calling the binary function on the first two items of the sequence, then on the result and the next item, and so on.

The del Statement  Unlike pop() method, it does not return a value.  To remove an item from a list: del myList[0]  To remove multiple items from a list: del myList[2:4]  To clear the entire list: del myList[:]  To delete entire variables: del myList

Tuple  Immutable – not possible to assign to the individual items  To create a tuple: myTuple1 = 666, 667, ‘six six eight’ Result: (666, 667, ‘six six eight’)  To create a nested tuple: myTuple2 = myTuple1, (1, 2, 3, 4) Result: ((666, 667, ‘six six eight’), (1, 2, 3, 4))  To create an empty tuple: emptyTuple = ()  To create a tuple with one item oneItemTuple = ‘tickle’,

Set  An unordered collection with no duplicate elements.  Basic uses Eliminating duplicate entries Membership testing  To create a set: myAnimals = [‘squirrel’, ‘fox’, ‘deer’, ‘squirrel’] mySet = set(myAnimals) Result: set([‘squirrel’, ‘fox’, ‘deer’])  Membership testing example: ‘squirrel’ in mySet Result: True ‘cat’ in mySet Result: False

Dictionary  Unlike sequences, dictionaries are indexed by keys.  Unordered set of key: value pairs  To create a dictionary: myDictionary = {‘toy’: ‘something to play with’, ‘food’: ‘something to eat’} dict([(‘toy’, ‘something to play with’), (‘food’, ‘something to eat’)])

The End  That is it!