Working with Lists 4
|
|
- Octavia Chandler
- 5 years ago
- Views:
Transcription
1 CS 61A Lecture 10
2 Announcements
3 Lists ['Demo']
4 Working with Lists 4
5 Working with Lists >>> digits = [1, 8, 2, 8] 4
6 Working with Lists >>> digits = [1, 8, 2, 8] >>> digits = [2//2, , 2, 2*2*2] 4
7 Working with Lists >>> digits = [1, 8, 2, 8] >>> digits = [2//2, , 2, 2*2*2] The number of elements 4
8 Working with Lists >>> digits = [1, 8, 2, 8] >>> digits = [2//2, , 2, 2*2*2] The number of elements >>> len(digits) 4 4
9 Working with Lists >>> digits = [1, 8, 2, 8] >>> digits = [2//2, , 2, 2*2*2] The number of elements >>> len(digits) 4 An element selected by its index 4
10 Working with Lists >>> digits = [1, 8, 2, 8] >>> digits = [2//2, , 2, 2*2*2] The number of elements >>> len(digits) 4 An element selected by its index >>> digits[3] 8 4
11 Working with Lists >>> digits = [1, 8, 2, 8] >>> digits = [2//2, , 2, 2*2*2] The number of elements >>> len(digits) 4 An element selected by its index >>> digits[3] 8 >>> getitem(digits, 3) 8 4
12 Working with Lists >>> digits = [1, 8, 2, 8] >>> digits = [2//2, , 2, 2*2*2] The number of elements >>> len(digits) 4 An element selected by its index >>> digits[3] 8 >>> getitem(digits, 3) 8 Concatenation and repetition 4
13 Working with Lists >>> digits = [1, 8, 2, 8] >>> digits = [2//2, , 2, 2*2*2] The number of elements >>> len(digits) 4 An element selected by its index >>> digits[3] 8 >>> getitem(digits, 3) 8 Concatenation and repetition >>> [2, 7] + digits * 2 [2, 7, 1, 8, 2, 8, 1, 8, 2, 8] 4
14 Working with Lists >>> digits = [1, 8, 2, 8] >>> digits = [2//2, , 2, 2*2*2] The number of elements >>> len(digits) 4 An element selected by its index >>> digits[3] 8 >>> getitem(digits, 3) 8 Concatenation and repetition >>> [2, 7] + digits * 2 [2, 7, 1, 8, 2, 8, 1, 8, 2, 8] >>> add([2, 7], mul(digits, 2)) [2, 7, 1, 8, 2, 8, 1, 8, 2, 8] 4
15 Working with Lists >>> digits = [1, 8, 2, 8] >>> digits = [2//2, , 2, 2*2*2] The number of elements >>> len(digits) 4 An element selected by its index >>> digits[3] 8 >>> getitem(digits, 3) 8 Concatenation and repetition >>> [2, 7] + digits * 2 [2, 7, 1, 8, 2, 8, 1, 8, 2, 8] >>> add([2, 7], mul(digits, 2)) [2, 7, 1, 8, 2, 8, 1, 8, 2, 8] Nested lists 4
16 Working with Lists >>> digits = [1, 8, 2, 8] >>> digits = [2//2, , 2, 2*2*2] The number of elements >>> len(digits) 4 An element selected by its index >>> digits[3] 8 >>> getitem(digits, 3) 8 Concatenation and repetition >>> [2, 7] + digits * 2 [2, 7, 1, 8, 2, 8, 1, 8, 2, 8] >>> add([2, 7], mul(digits, 2)) [2, 7, 1, 8, 2, 8, 1, 8, 2, 8] Nested lists >>> pairs = [[10, 20], [30, 40]] >>> pairs[1] [30, 40] >>> pairs[1][0] 30 4
17 Containers
18 Containers 6
19 Containers Built-in operators for testing whether an element appears in a compound value 6
20 Containers Built-in operators for testing whether an element appears in a compound value >>> digits = [1, 8, 2, 8] 6
21 Containers Built-in operators for testing whether an element appears in a compound value >>> digits = [1, 8, 2, 8] >>> 1 in digits True 6
22 Containers Built-in operators for testing whether an element appears in a compound value >>> digits = [1, 8, 2, 8] >>> 1 in digits True >>> 8 in digits True 6
23 Containers Built-in operators for testing whether an element appears in a compound value >>> digits = [1, 8, 2, 8] >>> 1 in digits True >>> 8 in digits True >>> 5 not in digits True 6
24 Containers Built-in operators for testing whether an element appears in a compound value >>> digits = [1, 8, 2, 8] >>> 1 in digits True >>> 8 in digits True >>> 5 not in digits True >>> not(5 in digits) True 6
25 Containers Built-in operators for testing whether an element appears in a compound value >>> digits = [1, 8, 2, 8] >>> 1 in digits True >>> 8 in digits True >>> 5 not in digits True >>> not(5 in digits) True (Demo) 6
26 For Statements (Demo)
27 Sequence Iteration 8
28 Sequence Iteration def count(s, value): total = 0 for element in s: if element == value: total = total + 1 return total 8
29 Sequence Iteration def count(s, value): total = 0 for element in s: Name bound in the first frame of the current environment (not a new frame) if element == value: total = total + 1 return total 8
30 For Statement Execution Procedure 9
31 For Statement Execution Procedure for <name> in <expression>: <suite> 9
32 For Statement Execution Procedure for <name> in <expression>: <suite> 1. Evaluate the header <expression>, which must yield an iterable value (a sequence) 9
33 For Statement Execution Procedure for <name> in <expression>: <suite> 1. Evaluate the header <expression>, which must yield an iterable value (a sequence) 2. For each element in that sequence, in order: 9
34 For Statement Execution Procedure for <name> in <expression>: <suite> 1. Evaluate the header <expression>, which must yield an iterable value (a sequence) 2. For each element in that sequence, in order: A. Bind <name> to that element in the current frame 9
35 For Statement Execution Procedure for <name> in <expression>: <suite> 1. Evaluate the header <expression>, which must yield an iterable value (a sequence) 2. For each element in that sequence, in order: A. Bind <name> to that element in the current frame B. Execute the <suite> 9
36 Sequence Unpacking in For Statements 10
37 Sequence Unpacking in For Statements >>> pairs = [[1, 2], [2, 2], [3, 2], [4, 4]] >>> same_count = 0 10
38 Sequence Unpacking in For Statements A sequence of fixed-length sequences >>> pairs = [[1, 2], [2, 2], [3, 2], [4, 4]] >>> same_count = 0 10
39 Sequence Unpacking in For Statements A sequence of fixed-length sequences >>> pairs = [[1, 2], [2, 2], [3, 2], [4, 4]] >>> same_count = 0 >>> for x, y in pairs:... if x == y:... same_count = same_count + 1 >>> same_count 2 10
40 Sequence Unpacking in For Statements A sequence of fixed-length sequences >>> pairs = [[1, 2], [2, 2], [3, 2], [4, 4]] >>> same_count = 0 A name for each element in a fixed-length sequence >>> for x, y in pairs:... if x == y:... same_count = same_count + 1 >>> same_count 2 10
41 Sequence Unpacking in For Statements A sequence of fixed-length sequences >>> pairs = [[1, 2], [2, 2], [3, 2], [4, 4]] >>> same_count = 0 A name for each element in a fixed-length sequence Each name is bound to a value, as in multiple assignment >>> for x, y in pairs:... if x == y:... same_count = same_count + 1 >>> same_count 2 10
42 Ranges
43 The Range Type A range is a sequence of consecutive integers. * 12
44 The Range Type A range is a sequence of consecutive integers. * * Ranges can actually represent more general integer sequences. 12
45 The Range Type A range is a sequence of consecutive integers. *..., -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5,... * Ranges can actually represent more general integer sequences. 12
46 The Range Type A range is a sequence of consecutive integers. *..., -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5,... range(-2, 2) * Ranges can actually represent more general integer sequences. 12
47 The Range Type A range is a sequence of consecutive integers. *..., -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5,... range(-2, 2) * Ranges can actually represent more general integer sequences. 12
48 The Range Type A range is a sequence of consecutive integers. *..., -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5,... range(-2, 2) * Ranges can actually represent more general integer sequences. 12
49 The Range Type A range is a sequence of consecutive integers. *..., -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5,... range(-2, 2) * Ranges can actually represent more general integer sequences. 12
50 The Range Type A range is a sequence of consecutive integers. *..., -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5,... Length: ending value - starting value range(-2, 2) * Ranges can actually represent more general integer sequences. 12
51 The Range Type A range is a sequence of consecutive integers. *..., -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5,... Length: ending value - starting value Element selection: starting value + index range(-2, 2) * Ranges can actually represent more general integer sequences. 12
52 The Range Type A range is a sequence of consecutive integers. *..., -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5,... Length: ending value - starting value Element selection: starting value + index range(-2, 2) >>> list(range(-2, 2)) [-2, -1, 0, 1] >>> list(range(4)) [0, 1, 2, 3] * Ranges can actually represent more general integer sequences. 12
53 The Range Type A range is a sequence of consecutive integers. *..., -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5,... Length: ending value - starting value Element selection: starting value + index range(-2, 2) >>> list(range(-2, 2)) [-2, -1, 0, 1] List constructor >>> list(range(4)) [0, 1, 2, 3] * Ranges can actually represent more general integer sequences. 12
54 The Range Type A range is a sequence of consecutive integers. *..., -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5,... Length: ending value - starting value Element selection: starting value + index range(-2, 2) >>> list(range(-2, 2)) [-2, -1, 0, 1] >>> list(range(4)) [0, 1, 2, 3] List constructor Range with a 0 starting value * Ranges can actually represent more general integer sequences. 12
55 The Range Type A range is a sequence of consecutive integers. *..., -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5,... range(-2, 2) Length: ending value - starting value Element selection: starting value + index (Demo) >>> list(range(-2, 2)) [-2, -1, 0, 1] >>> list(range(4)) [0, 1, 2, 3] List constructor Range with a 0 starting value * Ranges can actually represent more general integer sequences. 12
56 List Comprehensions
57 List Comprehensions >>> letters = ['a', 'b', 'c', 'd', 'e', 'f', 'm', 'n', 'o', 'p'] >>> [letters[i] for i in [3, 4, 6, 8]]
58 List Comprehensions >>> letters = ['a', 'b', 'c', 'd', 'e', 'f', 'm', 'n', 'o', 'p'] >>> [letters[i] for i in [3, 4, 6, 8]] ['d', 'e', 'm', 'o']
59 List Comprehensions 14
60 List Comprehensions [<map exp> for <name> in <iter exp> if <filter exp>] 14
61 List Comprehensions [<map exp> for <name> in <iter exp> if <filter exp>] Short version: [<map exp> for <name> in <iter exp>] 14
62 List Comprehensions [<map exp> for <name> in <iter exp> if <filter exp>] Short version: [<map exp> for <name> in <iter exp>] A combined expression that evaluates to a list using this evaluation procedure: 14
63 List Comprehensions [<map exp> for <name> in <iter exp> if <filter exp>] Short version: [<map exp> for <name> in <iter exp>] A combined expression that evaluates to a list using this evaluation procedure: 1. Add a new frame with the current frame as its parent 14
64 List Comprehensions [<map exp> for <name> in <iter exp> if <filter exp>] Short version: [<map exp> for <name> in <iter exp>] A combined expression that evaluates to a list using this evaluation procedure: 1. Add a new frame with the current frame as its parent 2. Create an empty result list that is the value of the expression 14
65 List Comprehensions [<map exp> for <name> in <iter exp> if <filter exp>] Short version: [<map exp> for <name> in <iter exp>] A combined expression that evaluates to a list using this evaluation procedure: 1. Add a new frame with the current frame as its parent 2. Create an empty result list that is the value of the expression 3. For each element in the iterable value of <iter exp>: 14
66 List Comprehensions [<map exp> for <name> in <iter exp> if <filter exp>] Short version: [<map exp> for <name> in <iter exp>] A combined expression that evaluates to a list using this evaluation procedure: 1. Add a new frame with the current frame as its parent 2. Create an empty result list that is the value of the expression 3. For each element in the iterable value of <iter exp>: A. Bind <name> to that element in the new frame from step 1 14
67 List Comprehensions [<map exp> for <name> in <iter exp> if <filter exp>] Short version: [<map exp> for <name> in <iter exp>] A combined expression that evaluates to a list using this evaluation procedure: 1. Add a new frame with the current frame as its parent 2. Create an empty result list that is the value of the expression 3. For each element in the iterable value of <iter exp>: A. Bind <name> to that element in the new frame from step 1 B. If <filter exp> evaluates to a true value, then add the value of <map exp> to the result list 14
68 Strings
69 Strings are an Abstraction 16
70 Strings are an Abstraction Representing data: '200' '1.2e-5' 'False' '[1, 2]' 16
71 Strings are an Abstraction Representing data: '200' '1.2e-5' 'False' '[1, 2]' Representing language: """And, as imagination bodies forth The forms of things unknown, the poet's pen Turns them to shapes, and gives to airy nothing A local habitation and a name. """ 16
72 Strings are an Abstraction Representing data: '200' '1.2e-5' 'False' '[1, 2]' Representing language: """And, as imagination bodies forth The forms of things unknown, the poet's pen Turns them to shapes, and gives to airy nothing A local habitation and a name. """ Representing programs: 'curry = lambda f: lambda x: lambda y: f(x, y)' 16
73 Strings are an Abstraction Representing data: '200' '1.2e-5' 'False' '[1, 2]' Representing language: """And, as imagination bodies forth The forms of things unknown, the poet's pen Turns them to shapes, and gives to airy nothing A local habitation and a name. """ Representing programs: 'curry = lambda f: lambda x: lambda y: f(x, y)' (Demo) 16
74 String Literals Have Three Forms >>> 'I am string!' 'I am string!' >>> "I've got an apostrophe" "I've got an apostrophe" >>> ' ' ' ' 17
75 String Literals Have Three Forms >>> 'I am string!' 'I am string!' >>> "I've got an apostrophe" "I've got an apostrophe" Single-quoted and double-quoted strings are equivalent >>> ' ' ' ' 17
76 String Literals Have Three Forms >>> 'I am string!' 'I am string!' >>> "I've got an apostrophe" "I've got an apostrophe" Single-quoted and double-quoted strings are equivalent >>> ' ' ' ' >>> """The Zen of Python claims, Readability counts. Read more: import this.""" 'The Zen of Python\nclaims, Readability counts.\nread more: import this.' 17
77 String Literals Have Three Forms >>> 'I am string!' 'I am string!' >>> "I've got an apostrophe" "I've got an apostrophe" Single-quoted and double-quoted strings are equivalent >>> ' ' ' ' >>> """The Zen of Python claims, Readability counts. Read more: import this.""" 'The Zen of Python\nclaims, Readability counts.\nread more: import this.' A backslash "escapes" the following character 17
78 String Literals Have Three Forms >>> 'I am string!' 'I am string!' >>> "I've got an apostrophe" "I've got an apostrophe" Single-quoted and double-quoted strings are equivalent >>> ' ' ' ' >>> """The Zen of Python claims, Readability counts. Read more: import this.""" 'The Zen of Python\nclaims, Readability counts.\nread more: import this.' A backslash "escapes" the following character "Line feed" character represents a new line 17
79 Dictionaries {'Dem': 0}
80 Limitations on Dictionaries 19
81 Limitations on Dictionaries Dictionaries are unordered collections of key-value pairs 19
82 Limitations on Dictionaries Dictionaries are unordered collections of key-value pairs Dictionary keys do have two restrictions: 19
83 Limitations on Dictionaries Dictionaries are unordered collections of key-value pairs Dictionary keys do have two restrictions: A key of a dictionary cannot be a list or a dictionary (or any mutable type) 19
84 Limitations on Dictionaries Dictionaries are unordered collections of key-value pairs Dictionary keys do have two restrictions: A key of a dictionary cannot be a list or a dictionary (or any mutable type) Two keys cannot be equal; There can be at most one value for a given key 19
85 Limitations on Dictionaries Dictionaries are unordered collections of key-value pairs Dictionary keys do have two restrictions: A key of a dictionary cannot be a list or a dictionary (or any mutable type) Two keys cannot be equal; There can be at most one value for a given key This first restriction is tied to Python's underlying implementation of dictionaries 19
86 Limitations on Dictionaries Dictionaries are unordered collections of key-value pairs Dictionary keys do have two restrictions: A key of a dictionary cannot be a list or a dictionary (or any mutable type) Two keys cannot be equal; There can be at most one value for a given key This first restriction is tied to Python's underlying implementation of dictionaries The second restriction is part of the dictionary abstraction 19
87 Limitations on Dictionaries Dictionaries are unordered collections of key-value pairs Dictionary keys do have two restrictions: A key of a dictionary cannot be a list or a dictionary (or any mutable type) Two keys cannot be equal; There can be at most one value for a given key This first restriction is tied to Python's underlying implementation of dictionaries The second restriction is part of the dictionary abstraction If you want to associate multiple values with a key, store them all in a sequence value 19
CS61A Lecture 15. Amir Kamil UC Berkeley February 25, 2013
CS61A Lecture 15 Amir Kamil UC Berkeley February 25, 2013 Announcements HW5 due on Wednesday Trends project out Partners are required; find one in lab or on Piazza Will not work in IDLE New bug submission
More information61A LECTURE 8 SEQUENCES, ITERABLES
61A LECTURE 8 SEQUENCES, ITERABLES Steven Tang and Eric Tzeng July 8, 013 Announcements Homework 4 due tonight Homework 5 is out, due Friday Midterm is Thursday, 7pm Thanks for coming to the potluck! What
More information61A LECTURE 8 SEQUENCES, ITERABLES. Steven Tang and Eric Tzeng July 8, 2013
61A LECTURE 8 SEQUENCES, ITERABLES Steven Tang and Eric Tzeng July 8, 2013 Announcements Homework 4 due tonight Homework 5 is out, due Friday Midterm is Thursday, 7pm Thanks for coming to the potluck!
More informationCS61A Lecture 16. Amir Kamil UC Berkeley February 27, 2013
CS61A Lecture 16 Amir Kamil UC Berkeley February 27, 2013 Announcements HW5 due tonight Trends project due on Tuesday Partners are required; find one in lab or on Piazza Will not work in IDLE New bug submission
More informationCS61A Lecture 16. Amir Kamil UC Berkeley February 27, 2013
CS61A Lecture 16 Amir Kamil UC Berkeley February 27, 2013 Announcements HW5 due tonight Trends project due on Tuesday Partners are required; find one in lab or on Piazza Will not work in IDLE New bug submission
More informationSCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015
SCHEME 7 COMPUTER SCIENCE 61A October 29, 2015 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,
More informationPython List built-in methods, accessing elements, selection, slicing, recursive functions, list comprehension
ITP 20005 Programming Languages Chapter 2 Building Abstractions with Data 2.1 Introduction 2.2 Data Abstraction 2.3 Sequences List, Tuple, String, Linked List Major references: 1. Structure and Interpretation
More informationChapter 2: Building Abstractions with Data
Chapter 2: Building Abstractions with Data Contents 2.1 Introduction 1 2.2 Data Abstraction 1 2.2.1 Example: Arithmetic on Rational Numbers............................. 2 2.2.2 Tuples................................................
More informationSCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017
SCHEME 8 COMPUTER SCIENCE 61A March 2, 2017 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,
More information\n is used in a string to indicate the newline character. An expression produces data. The simplest expression
Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of
More informationChapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.
Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of
More informationTeaching London Computing
Teaching London Computing A Level Computer Science Topic 3: Advanced Programming in Python William Marsh School of Electronic Engineering and Computer Science Queen Mary University of London Aims Further
More informationChapter 2: Building Abstractions with Objects
Chapter 2: Building Abstractions with Objects Contents 2.1 Introduction 1 2.1.1 The Object Metaphor........................................ 1 2.1.2 Native Data Types..........................................
More informationIntroduction to Bioinformatics
Introduction to Bioinformatics Variables, Data Types, Data Structures, Control Structures Janyl Jumadinova February 3, 2016 Data Type Data types are the basic unit of information storage. Instances of
More informationSpring 2018 Discussion 7: March 21, Introduction. 2 Primitives
CS 61A Scheme Spring 2018 Discussion 7: March 21, 2018 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme
More informationFall 2017 Discussion 7: October 25, 2017 Solutions. 1 Introduction. 2 Primitives
CS 6A Scheme Fall 207 Discussion 7: October 25, 207 Solutions Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write
More informationCS1 Lecture 12 Feb. 11, 2019
CS1 Lecture 12 Feb. 11, 2019 HW4 available tomorrow, due next Wed. Discussion sections this week will be closely tied to one of the homework problems. Exam 1, Thursday evening, 2/21, 6:30-8:00pm HW2 scores
More informationFunctional programming in LISP
Programming Languages Week 4 Functional programming in LISP College of Information Science and Engineering Ritsumeikan University review of part 3 enumeration of dictionaries you receive a sequence of
More informationc) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.
2.1 Introduction (No questions.) 2.2 A Simple Program: Printing a Line of Text 2.1 Which of the following must every C program have? (a) main (b) #include (c) /* (d) 2.2 Every statement in C
More informationSummer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define
CS 6A Scheme Summer 207 Discussion 0: July 25, 207 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,
More informationCSCE 110 Programming I Basics of Python: Variables, Expressions, Input/Output
CSCE 110 Programming I Basics of Python: Variables, Expressions, Input/Output Dr. Tiffani L. Williams Department of Computer Science and Engineering Texas A&M University Spring 2011 Python Python was developed
More informationCPSC 217 Midterm (Python 3 version)
CPSC 217 Midterm (Python 3 version) Duration: 60 minutes 7 March 2011 This exam has 81 questions and 14 pages. This exam is closed book. No notes, books, calculators or electronic devices, or other assistance
More informationPython Basics. Lecture and Lab 5 Day Course. Python Basics
Python Basics Lecture and Lab 5 Day Course Course Overview Python, is an interpreted, object-oriented, high-level language that can get work done in a hurry. A tool that can improve all professionals ability
More informationBabu Madhav Institute of Information Technology, UTU 2015
Five years Integrated M.Sc.(IT)(Semester 5) Question Bank 060010502:Programming in Python Unit-1:Introduction To Python Q-1 Answer the following Questions in short. 1. Which operator is used for slicing?
More informationFull file at C How to Program, 6/e Multiple Choice Test Bank
2.1 Introduction 2.2 A Simple Program: Printing a Line of Text 2.1 Lines beginning with let the computer know that the rest of the line is a comment. (a) /* (b) ** (c) REM (d)
More informationOverview: Programming Concepts. Programming Concepts. Names, Values, And Variables
Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript Fluency with Information Technology Third Edition by Lawrence Snyder Overview: Programming Concepts Programming: Act of formulating
More informationOverview: Programming Concepts. Programming Concepts. Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript
Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript Fluency with Information Technology Third Edition by Lawrence Snyder Overview: Programming Concepts Programming: Act of formulating
More informationStreams, Delayed Evaluation and a Normal Order Interpreter. CS 550 Programming Languages Jeremy Johnson
Streams, Delayed Evaluation and a Normal Order Interpreter CS 550 Programming Languages Jeremy Johnson 1 Theme This lecture discusses the stream model of computation and an efficient method of implementation
More informationScheme in Scheme: The Metacircular Evaluator Eval and Apply
Scheme in Scheme: The Metacircular Evaluator Eval and Apply CS21b: Structure and Interpretation of Computer Programs Brandeis University Spring Term, 2015 The metacircular evaluator is A rendition of Scheme,
More informationIntroduction to Python: Data types. HORT Lecture 8 Instructor: Kranthi Varala
Introduction to Python: Data types HORT 59000 Lecture 8 Instructor: Kranthi Varala Why Python? Readability and ease-of-maintenance Python focuses on well-structured easy to read code Easier to understand
More informationENGR 101 Engineering Design Workshop
ENGR 101 Engineering Design Workshop Lecture 2: Variables, Statements/Expressions, if-else Edgardo Molina City College of New York Literals, Variables, Data Types, Statements and Expressions Python as
More informationLecture 16: Static Semantics Overview 1
Lecture 16: Static Semantics Overview 1 Lexical analysis Produces tokens Detects & eliminates illegal tokens Parsing Produces trees Detects & eliminates ill-formed parse trees Static semantic analysis
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 3 Thomas Wies New York University Review Last week Names and Bindings Lifetimes and Allocation Garbage Collection Scope Outline Control Flow Sequencing
More informationFall 2018 Discussion 8: October 24, 2018 Solutions. 1 Introduction. 2 Primitives
CS 6A Scheme Fall 208 Discussion 8: October 24, 208 Solutions Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write
More informationAdvanced Algorithms and Computational Models (module A)
Advanced Algorithms and Computational Models (module A) Giacomo Fiumara giacomo.fiumara@unime.it 2014-2015 1 / 34 Python's built-in classes A class is immutable if each object of that class has a xed value
More informationShell CSCE 314 TAMU. Haskell Functions
1 CSCE 314: Programming Languages Dr. Dylan Shell Haskell Functions 2 Outline Defining Functions List Comprehensions Recursion 3 Conditional Expressions As in most programming languages, functions can
More informationUNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger
UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division CS 164 Spring 2005 P. N. Hilfinger Project #2: Static Analyzer for Pyth Due: Wednesday, 6 April
More informationWorking with Strings. Husni. "The Practice of Computing Using Python", Punch & Enbody, Copyright 2013 Pearson Education, Inc.
Working with Strings Husni "The Practice of Computing Using Python", Punch & Enbody, Copyright 2013 Pearson Education, Inc. Sequence of characters We've talked about strings being a sequence of characters.
More informationScheme as implemented by Racket
Scheme as implemented by Racket (Simple view:) Racket is a version of Scheme. (Full view:) Racket is a platform for implementing and using many languages, and Scheme is one of those that come out of the
More informationHomework 7: Subsets Due: 11:59 PM, Oct 23, 2018
CS17 Integrated Introduction to Computer Science Klein Contents Homework 7: Subsets Due: 11:59 PM, Oct 23, 2018 1 Bookends (Practice) 2 2 Subsets 3 3 Subset Sum 4 4 k-subsets 5 5 k-subset Sum 5 Objectives
More information61A Lecture 6. Friday, September 7
61A Lecture 6 Friday, September 7 Lambda Expressions >>> ten = 10 An expression: this one evaluates to a number >>> square = x * x Also an expression: evaluates to a function >>> square = lambda x: x *
More informationCS1 Lecture 3 Jan. 18, 2019
CS1 Lecture 3 Jan. 18, 2019 Office hours for Prof. Cremer and for TAs have been posted. Locations will change check class website regularly First homework assignment will be available Monday evening, due
More informationVHDL Lexical Elements
1 Design File = Sequence of Lexical Elements && Separators (a) Separators: Any # of Separators Allowed Between Lexical Elements 1. Space character 2. Tab 3. Line Feed / Carriage Return (EOL) (b) Lexical
More informationStructure and Interpretation of Computer Programs Spring 2014 Final (with corrections)
CS 61A Structure and Interpretation of Computer Programs Spring 2014 Final (with corrections) INSTRUCTIONS You have 3 hours to complete the exam. The exam is open book and open notes. You may not use a
More informationHaskell: Lists. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Friday, February 24, Glenn G.
Haskell: Lists CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Friday, February 24, 2017 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks
More informationCS 61A Interpreters, Tail Calls, Macros, Streams, Iterators. Spring 2019 Guerrilla Section 5: April 20, Interpreters.
CS 61A Spring 2019 Guerrilla Section 5: April 20, 2019 1 Interpreters 1.1 Determine the number of calls to scheme eval and the number of calls to scheme apply for the following expressions. > (+ 1 2) 3
More informationIntroduction to Scheme
How do you describe them Introduction to Scheme Gul Agha CS 421 Fall 2006 A language is described by specifying its syntax and semantics Syntax: The rules for writing programs. We will use Context Free
More informationWhile Loops A while loop executes a statement as long as a condition is true while condition: statement(s) Statement may be simple or compound Typical
Recommended Readings Chapter 5 Topic 5: Repetition Are you saying that I am redundant? That I repeat myself? That I say the same thing over and over again? 1 2 Repetition So far, we have learned How to
More informationCS1 Lecture 3 Jan. 22, 2018
CS1 Lecture 3 Jan. 22, 2018 Office hours for me and for TAs have been posted, locations will change check class website regularly First homework available, due Mon., 9:00am. Discussion sections tomorrow
More informationPython Evaluation Rules
Python Evaluation Rules UW CSE 160 https://courses.cs.washington.edu/courses/cse160/15sp/ Michael Ernst and Isaac Reynolds mernst@cs.washington.edu April 1, 2015 Contents 1 Introduction 2 1.1 The Structure
More informationChapter 17. Fundamental Concepts Expressed in JavaScript
Chapter 17 Fundamental Concepts Expressed in JavaScript Learning Objectives Tell the difference between name, value, and variable List three basic data types and the rules for specifying them in a program
More informationLecture 3. Input, Output and Data Types
Lecture 3 Input, Output and Data Types Goals for today Variable Types Integers, Floating-Point, Strings, Booleans Conversion between types Operations on types Input/Output Some ways of getting input, and
More informationCSCE 110 Programming I
CSCE 110 Programming I Basics of Python (Part 1): Variables, Expressions, and Input/Output Dr. Tiffani L. Williams Department of Computer Science and Engineering Texas A&M University Spring 2013 Tiffani
More informationSequence of Characters. Non-printing Characters. And Then There Is """ """ Subset of UTF-8. String Representation 6/5/2018.
Chapter 4 Working with Strings Sequence of Characters we've talked about strings being a sequence of characters. a string is indicated between ' ' or " " the exact sequence of characters is maintained
More informationENGR 102 Engineering Lab I - Computation
ENGR 102 Engineering Lab I - Computation Learning Objectives by Week 1 ENGR 102 Engineering Lab I Computation 2 Credits 2. Introduction to the design and development of computer applications for engineers;
More informationSCHEME 10 COMPUTER SCIENCE 61A. July 26, Warm Up: Conditional Expressions. 1. What does Scheme print? scm> (if (or #t (/ 1 0)) 1 (/ 1 0))
SCHEME 0 COMPUTER SCIENCE 6A July 26, 206 0. Warm Up: Conditional Expressions. What does Scheme print? scm> (if (or #t (/ 0 (/ 0 scm> (if (> 4 3 (+ 2 3 4 (+ 3 4 (* 3 2 scm> ((if (< 4 3 + - 4 00 scm> (if
More informationCSE : Python Programming
CSE 399-004: Python Programming Lecture 08: Graphical User Interfaces with wxpython March 12, 2005 http://www.seas.upenn.edu/~cse39904/ Plan for today and next time Today: wxpython (part 1) Aside: Arguments
More informationAnnouncements for this Lecture
Lecture 6 Objects Announcements for this Lecture Last Call Quiz: About the Course Take it by tomorrow Also remember survey Assignment 1 Assignment 1 is live Posted on web page Due Thur, Sep. 18 th Due
More informationIn addition to the primary macro syntax, the system also supports several special macro types:
The system identifies macros using special parentheses. You need to enclose macro expressions into curly brackets and the percentage symbol: {% expression %} Kentico provides an object-oriented language
More informationRuby: Introduction, Basics
Ruby: Introduction, Basics Computer Science and Engineering College of Engineering The Ohio State University Lecture 4 Ruby vs Java: Similarities Imperative and object-oriented Classes and instances (ie
More informationC Basics. Chapter 2: C Basics. C Programming Language. v3.3 February 6, 2017
Chapter 2: C Programming Language Šimon Řeřucha v3.3 February 6, 2017 There are only two kinds of programming languages: those people always bitch about and those nobody uses. Bjarne Stroustrup. General
More informationLecture #12: Mutable Data. Last modified: Sun Feb 19 17:15: CS61A: Lecture #12 1
Lecture #12: Mutable Data Last modified: Sun Feb 19 17:15:18 2017 CS61A: Lecture #12 1 Using Mutability For Construction: map rlist Revisited Even if we never change a data structure once it is constructed,
More informationIntroduction to Python
Introduction to Python Version 1.1.5 (12/29/2008) [CG] Page 1 of 243 Introduction...6 About Python...7 The Python Interpreter...9 Exercises...11 Python Compilation...12 Python Scripts in Linux/Unix & Windows...14
More informationDSC 201: Data Analysis & Visualization
DSC 201: Data Analysis & Visualization Classes Dr. David Koop Tuple, List, Dictionary, or Set? [1,2,"abc"] 2 Tuple, List, Dictionary, or Set? {"a", 1, 2} 3 Tuple, List, Dictionary, or Set? {} 4 Tuple,
More informationCOMP1730/COMP6730 Programming for Scientists. Strings
COMP1730/COMP6730 Programming for Scientists Strings Lecture outline * Sequence Data Types * Character encoding & strings * Indexing & slicing * Iteration over sequences Sequences * A sequence contains
More informationPython in 10 (50) minutes
Python in 10 (50) minutes https://www.stavros.io/tutorials/python/ Python for Microcontrollers Getting started with MicroPython Donald Norris, McGrawHill (2017) Python is strongly typed (i.e. types are
More information61A Lecture 3. Friday, September 5
61A Lecture 3 Friday, September 5 Announcements There's plenty of room in live lecture if you want to come (but videos are still better) Please don't make noise outside of the previous lecture! Homework
More informationAlgorithmic Thinking: Computing with Lists
Algorithmic Thinking: Computing with Lists So Far in Python Data types: int, float, Boolean, string Assignments, function definitions Control structures: For loops, while loops, conditionals Last Lecture
More informationSECOND EDITION SAMPLE CHAPTER. First edition by Daryl K. Harms Kenneth M. McDonald. Naomi R. Ceder MANNING
SECOND EDITION SECOND EDITION Covers Python 3 SAMPLE CHAPTER First edition by Daryl K. Harms Kenneth M. McDonald Naomi R. Ceder MANNING The Quick Python Book Second Edition by Naomi R. Ceder Chapter 8
More informationPYTHON DATA SCIENCE TOOLBOX II. List comprehensions
PYTHON DATA SCIENCE TOOLBOX II List comprehensions Populate a list with a for loop In [1]: nums = [12, 8, 21, 3, 16] In [2]: new_nums = [] In [3]: for num in nums:...: new_nums.append(num + 1) In [4]:
More informationVariables, Constants, and Data Types
Variables, Constants, and Data Types Strings and Escape Characters Primitive Data Types Variables, Initialization, and Assignment Constants Reading for this lecture: Dawson, Chapter 2 http://introcs.cs.princeton.edu/python/12types
More informationLISTS WITH PYTHON. José M. Garrido Department of Computer Science. May College of Computing and Software Engineering Kennesaw State University
LISTS WITH PYTHON José M. Garrido Department of Computer Science May 2015 College of Computing and Software Engineering Kennesaw State University c 2015, J. M. Garrido Lists with Python 2 Lists with Python
More informationLearning Language. Reference Manual. George Liao (gkl2104) Joseanibal Colon Ramos (jc2373) Stephen Robinson (sar2120) Huabiao Xu(hx2104)
Learning Language Reference Manual 1 George Liao (gkl2104) Joseanibal Colon Ramos (jc2373) Stephen Robinson (sar2120) Huabiao Xu(hx2104) A. Introduction Learning Language is a programming language designed
More informationMUTABLE LISTS AND DICTIONARIES 4
MUTABLE LISTS AND DICTIONARIES 4 COMPUTER SCIENCE 61A Sept. 24, 2012 1 Lists Lists are similar to tuples: the order of the data matters, their indices start at 0. The big difference is that lists are mutable
More informationPython Basics. 1 of 7 9/5/2018, 8:51 AM. txt1 = "ada lovelace, english mathematician and writer" print(txt1)
1 of 7 9/5/2018, 8:51 AM Python Basics In [1]: txt1 = "ada lovelace, english mathematician and writer" print(txt1) ada lovelace, english mathematician and writer Here txt1 is a variable and "ada lovelace,
More informationLevel 3 Computing Year 2 Lecturer: Phil Smith
Level 3 Computing Year 2 Lecturer: Phil Smith We looked at: Previously Reading and writing files. BTEC Level 3 Year 2 Unit 16 Procedural programming Now Now we will look at: Appending data to existing
More informationQUark Language Reference Manual
QUark Language Reference Manual Daria Jung (djj2115), Jamis Johnson (jmj2180), Jim Fan (lf2422), Parthiban Loganathan (pl2487) Introduction This is the reference manual for QUark, a high level language
More informationCopied from: https://www.cs.hmc.edu/twiki/bin/view/cs5/lab1b on 3/20/2017
Hw 1, Part 2 (Lab): Functioning smoothly! Using built-in functions Copied from: https://www.cs.hmc.edu/twiki/bin/view/cs5/lab1b on 3/20/2017 First, try out some of Python's many built-in functions. These
More informationHarvard School of Engineering and Applied Sciences CS 152: Programming Languages
Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Lecture 18 Thursday, March 29, 2018 In abstract algebra, algebraic structures are defined by a set of elements and operations
More informationSCHEME The Scheme Interpreter. 2 Primitives COMPUTER SCIENCE 61A. October 29th, 2012
SCHEME COMPUTER SCIENCE 6A October 29th, 202 In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs, we will eventually
More informationCMSC201 Computer Science I for Majors
CMSC201 Computer Science I for Majors Lecture 09 Strings Last Class We Covered Lists and what they are used for Getting the length of a list Operations like append() and remove() Iterating over a list
More informationAnd Parallelism. Parallelism in Prolog. OR Parallelism
Parallelism in Prolog And Parallelism One reason that Prolog is of interest to computer scientists is that its search mechanism lends itself to parallel evaluation. In fact, it supports two different kinds
More informationSCHEME AND CALCULATOR 5b
SCHEME AND CALCULATOR 5b COMPUTER SCIENCE 6A July 25, 203 In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,
More informationAl al-bayt University Prince Hussein Bin Abdullah College for Information Technology Computer Science Department
Al al-bayt University Prince Hussein Bin Abdullah College for Information Technology Computer Science Department 0901212 Python Programming 1 st Semester 2014/2015 Course Catalog This course introduces
More informationGetting Started Values, Expressions, and Statements CS GMU
Getting Started Values, Expressions, and Statements CS 112 @ GMU Topics where does code go? values and expressions variables and assignment 2 where does code go? we can use the interactive Python interpreter
More informationChapter 2 Working with Data Types and Operators
JavaScript, Fourth Edition 2-1 Chapter 2 Working with Data Types and Operators At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics
More informationLecture 7: Lambda & Abstract Data Types
UC Berkeley EECS Adj. Ass. Prof. Dr. Gerald Friedland Computational Structures in Data Science Lecture 7: Lambda & Abstract Data Types Computational Concepts Toolbox Data type: values, literals, operations,
More informationCS2304: Python for Java Programmers. CS2304: Sequences and Collections
CS2304: Sequences and Collections Sequences In Python A sequence type in python supports: The in membership operator. The len() function. Slicing like we saw with strings, s[1:3]. And is iterable (for
More informationThis exam is worth 70 points, or about 23% of your total course grade. The exam contains 15 questions.
CS 61A Final Exam May 16, 2008 Your name login: cs61a This exam is worth 70 points, or about 23% of your total course grade. The exam contains 15 questions. This booklet contains 18 numbered pages including
More informationCMSC201 Computer Science I for Majors
CMSC201 Computer Science I for Majors Lecture 09 Strings Last Class We Covered Lists and what they are used for Getting the length of a list Operations like append() and remove() Iterating over a list
More informationLecture #12: Mutable Data. map rlist Illustrated (III) map rlist Illustrated. Using Mutability For Construction: map rlist Revisited
Lecture #12: Mutable Data Using Mutability For Construction: map rlist Revisited Even if we never change a data structure once it is constructed, mutation may be useful during its construction. Example:
More informationLecture 10: Strings. CS1068+ Introductory Programming in Python. Dr Kieran T. Herley 2018/19. Department of Computer Science University College Cork
Lecture 10: Strings CS1068+ Introductory Programming in Python Dr Kieran T. Herley 2018/19 Department of Computer Science University College Cork Summary 1 Python text: data type str String sequences of
More informationA Small Interpreted Language
A Small Interpreted Language What would you need to build a small computing language based on mathematical principles? The language should be simple, Turing equivalent (i.e.: it can compute anything that
More informationA First Look at ML. Chapter Five Modern Programming Languages, 2nd ed. 1
A First Look at ML Chapter Five Modern Programming Languages, 2nd ed. 1 ML Meta Language One of the more popular functional languages (which, admittedly, isn t saying much) Edinburgh, 1974, Robin Milner
More information61A Lecture 4. Monday, September 9
61A Lecture 4 Monday, September 9 Announcements Homework 1 due Tuesday 9/10 at 5pm; Late homework is not accepted! Quiz on Wednesday 9/11 released at 1pm, due Thursday 9/12 at 11:59pm Open-computer: You
More informationENVIRONMENT DIAGRAMS AND RECURSION 2
ENVIRONMENT DIAGRAMS AND RECURSION 2 COMPUTER SCIENCE 61A February 4, 2016 1 Environment Diagrams An environment diagram keeps track of all the variables that have been defined and the values they are
More informationLECTURE 3 Python Basics Part 2
LECTURE 3 Python Basics Part 2 FUNCTIONAL PROGRAMMING TOOLS Last time, we covered function concepts in depth. We also mentioned that Python allows for the use of a special kind of function, a lambda function.
More informationCIS192: Python Programming
CIS192: Python Programming Functions and Functional Programming Harry Smith University of Pennsylvania January 25, 2018 Harry Smith (University of Pennsylvania) CIS 192 Lecture 3 January 25, 2018 1 / 39
More informationC311 Lab #3 Representation Independence: Representation Independent Interpreters
C311 Lab #3 Representation Independence: Representation Independent Interpreters Will Byrd webyrd@indiana.edu February 5, 2005 (based on Professor Friedman s lecture on January 29, 2004) 1 Introduction
More informationFunctions, Scope & Arguments. HORT Lecture 12 Instructor: Kranthi Varala
Functions, Scope & Arguments HORT 59000 Lecture 12 Instructor: Kranthi Varala Functions Functions are logical groupings of statements to achieve a task. For example, a function to calculate the average
More information