CSC108H1 Lecture Notes - Lecture 8: Lazy Evaluation, Operand, Operon

121 views2 pages
10 Apr 2016
School
Course
yifanyang and 39659 others unlocked
CSC108H1 Full Course Notes
21
CSC108H1 Full Course Notes
Verified Note
21 documents

Document Summary

Algorithm 1: reverse the string -> compare reversed string to original: rev = " for ch in s: rev = ch + rev return s == rev(s) Algorithm 2: split string into two halves -> reverse the second half -> compare: n = len(s) return s[ : n//2] == reverse(s[n n//2: ] Can be broken down based on ratings, price, cuisine. Use dictionaries which can be {str : int} -> ratings or {str : list of str} -> price/cuisine e. g. price_to_names = { $" : [ queen st. caf "] } Def recommend (file, price, cuisines_list): use a constant for file name containing the data, filename = restaurants_small. txt", read the file and build the data structure, read_restaurants(file) = names_to_rating, price_to_names, cuisine_to_names. Import doctest -> doctest. testmod() -> test results will show. Lazy evaluation: if the first operand in an and expression is false, the and expression evaluates to false.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents