Sample lecture slides.

Slides:



Advertisements
Similar presentations
Course A201: Introduction to Programming 10/28/2010.
Advertisements

Container Types in Python
Dictionaries: Keeping track of pairs
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.
Lists Introduction to Computing Science and Programming I.
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.
Python Lists and Such CS 4320, SPRING List Functions len(s) is the length of list s s + t is the concatenation of lists s and t s.append(x) adds.
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.
Built-in Data Structures in Python An Introduction.
Lists. The list is a most versatile datatype available in Python which can be written as a list of comma-separated values (items) between square brackets.
Tuples Chapter 10 Python for Informatics: Exploring Information
LECTURE 3 Python Basics Part 2. FUNCTIONAL PROGRAMMING TOOLS Last time, we covered function concepts in depth. We also mentioned that Python allows for.
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.
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.
Python Fundamentals: Complex Data Structures Eric Shook Department of Geography Kent State University.
Guide to Programming with Python Chapter Four Strings, and Tuples; for Loops: The Word Jumble Game.
1 i206: Lecture 17: Exam 2 Prep ; Intro to Regular Expressions Marti Hearst Spring 2012.
Advanced Python Idioms
Lecture 3 Python Basics Part 2.
Generating Random Numbers
CMSC201 Computer Science I for Majors Lecture 17 – Dictionaries
CMSC201 Computer Science I for Majors Lecture 21 – Dictionaries
When to use Tuples instead of Lists
Week 3 - Friday CS221.
Data types: Complex types (Dictionaries)
Ruth Anderson CSE 140 University of Washington
Tuples Chapter 10 Python for Everybody
LING 388: Computers and Language
CS313D: Advanced Programming Language
CISC101 Reminders Quiz 2 this week.
Bryan Burlingame 03 October 2018
Popping Items Off a Stack Lesson xx
Bryan Burlingame Halloween 2018
CHAPTER THREE Sequences.
LING/C SC/PSYC 438/538 Lecture 6 Sandiway Fong.
CS190/295 Programming in Python for Life Sciences: Lecture 6
Data Structures – 1D Lists
CISC101 Reminders Quiz 1 grading underway Next Quiz, next week.
Python Data Structures
Python for Informatics: Exploring Information
String and Lists Dr. José M. Reyes Álamo.
Ruth Anderson UW CSE 160 Winter 2017
CS 1111 Introduction to Programming Fall 2018
Winter 2019 CISC101 2/17/2019 CISC101 Reminders
Michael Ernst CSE 140 University of Washington
Dictionaries: Keeping track of pairs
Advanced Python Idioms
CISC101 Reminders Assignment 2 due today.
CHAPTER 4: Lists, Tuples and Dictionaries
Advanced Python Idioms
Ruth Anderson CSE 160 University of Washington
15-110: Principles of Computing
EN Software Carpentry Python – A Crash Course Data Structures.
Bryan Burlingame Halloween 2018
Ruth Anderson UW CSE 160 Spring 2018
CSE 231 Lab 8.
Winter 2019 CISC101 5/26/2019 CISC101 Reminders
Introduction to Dictionaries
Python Open source Many applications Python 3 jupyter notebook
CMSC201 Computer Science I for Majors Lecture 19 – Dictionaries
Dictionary.
Python List.
Python - Tuples.
LING/C SC/PSYC 438/538 Lecture 7 Sandiway Fong.
Introduction to Python
Tuple.
Introduction to Computer Science
Selamat Datang di “Programming Essentials in Python”
Ruth Anderson UW CSE 160 Winter 2016
Presentation transcript:

Sample lecture slides

Python: basic data types https://docs.python.org/3/tutorial/introduction.html Numbers (done) Strings Lists Dictionaries

Strings

Python: basic data types https://docs.python.org/3/tutorial/introduction.html Numbers Strings Lists Dictionaries

Python Lists Recall strings from last time? Think of those as lists too

Python Lists vs. Sets set is faster than list for lookup (hashtable) in – membership not in – not a member of set(List) - produces a set, no duplicates permitted set is faster than list for lookup (hashtable)

Python Lists

Python Lists Lists as stacks Lists as queues https://visualgo.net/en/list?slide=4 Lists as stacks Lists as queues List Comprehensions (advanced topic) https://www.appcoda.com/ios-concurrency/

Python List as a Queue Method append() to add to the queue list[0] gives us the head of the queue list = list[1:] deletes the head of the queue from the queue EXAMPLE:

Python https://docs.python.org/3/tutorial/introduction.html Numbers Strings Lists Dictionaries

Python Lists Lists as stacks Lists as queues https://visualgo.net/en/list?slide=4 Lists as stacks Lists as queues List Comprehensions (advanced topic) https://www.appcoda.com/ios-concurrency/

Python List as a Queue Method append() to add to the queue EXAMPLE: Method append() to add to the queue list[0] gives us the head of the queue list = list[1:] deletes the head of the queue from the queue Also can use del list[0]

Python List as a Queue A faster implementation according to section 5.1.2

Python List as a Stack pop() removes from the same end as append()

Tuples See use with dictionaries later … Section 5.3: note instead of square brackets, round brackets are used See use with dictionaries later …

Dictionaries (dict) Lists and tuples are indexed by whole numbers (from 0) Dictionaries are indexed by a key (usually a string) and return some value associated with the key Note: use of curly braces Dictionaries are not ordered (like sets) – see next slide Methods keys(), values(), items() Refer to key + value as an item: encoded as a tuple

Dictionaries (dict) Example from class…

Dictionaries (dict) Python 3.6 Dictionary order preservation depends on the version of Python used … Python 3.6

Dictionaries (dict) How to print the contents of a dictionary? Use a for-loop and method items(): k,v is a tuple

Dictionaries (dict) All values are lists Advantage: simplifies the code Trade-off Values are lists or a string Advantage: simpler-looking dict

Dictionaries Works too! Less transparent: relies on a Python-particuar quirk …

Dictionaries (dict) function zip() pairs up elements from two lists into an iterable

Dictionaries (dict) function zip() doesn't always work quite the same …

For loops and range() range(start,stop,step) returns an iterable that can be used with a for- loop range(stop) start assumed to be 0; step assumed to be 1; range does not include stop

For loops and range() Ranges can be indexed like a list Can use in and not in