CSC108H1 Lecture Notes - Lecture 8: Lazy Evaluation, Operand, Operon
yifanyang and 39659 others unlocked
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.