LING 388: Computers and Language

Slides:



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

Dictionaries: Keeping track of pairs
COMPUTER SCIENCE FEBRUARY 2011 Lists in Python. Introduction to Lists Lists (aka arrays): an ordered set of elements  A compound data type, like strings.
Python Data Structures
Stacks and Queues Introduction to Computing Science and Programming I.
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.
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
CS190/295 Programming in Python for Life Sciences: Lecture 6 Instructor: Xiaohui Xie University of California, Irvine.
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.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 3: Built-in functions.
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.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 10: Files.
Data Structures Intro2CS – week Stack ADT (Abstract Data Type) A container with 3 basic actions: – push(item) – pop() – is_empty() Semantics: –
1 i206: Lecture 17: Exam 2 Prep ; Intro to Regular Expressions Marti Hearst Spring 2012.
String and Lists Dr. José M. Reyes Álamo.
Advanced Python Idioms
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.
Dictionaries, File operations
CISC101 Reminders Quiz 2 this week.
File Handling Programming Guides.
Bryan Burlingame 03 October 2018
Bryan Burlingame Halloween 2018
LING 388: Computers and Language
CISC101 Reminders Slides have changed from those posted last night…
LING/C SC/PSYC 438/538 Lecture 6 Sandiway Fong.
Guide to Programming with Python
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
CISC101 Reminders Quiz 2 this week.
Python for Informatics: Exploring Information
String and Lists Dr. José M. Reyes Álamo.
Introduction to Dictionaries
CSCE 590 Web Scraping: Lecture 2
CS 1111 Introduction to Programming Fall 2018
Dictionaries Dictionary: object that stores a collection of data
Winter 2019 CISC101 2/17/2019 CISC101 Reminders
15-110: Principles of Computing
For loops Taken from notes by Dr. Neil Moore
Advanced Python Idioms
CISC101 Reminders Assignment 2 due today.
CHAPTER 4: Lists, Tuples and Dictionaries
Advanced Python Idioms
15-110: Principles of Computing
EN Software Carpentry Python – A Crash Course Data Structures.
Fundaments of Game Design
Bryan Burlingame Halloween 2018
CSCE 590 Web Scraping: Lecture 2
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
Sample lecture slides.
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”
Presentation transcript:

LING 388: Computers and Language Lecture 6

Today's Topics Reminder Homework 3 on Summarization and Clickbait due tomorrow (midnight) Python introduction contd.

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