CSC148H1 Lecture Notes - Lecture 17: List Comprehension

78 views4 pages
13 Mar 2018
School
Course
Professor
katrinasavvy and 38715 others unlocked
CSC148H1 Full Course Notes
1
CSC148H1 Full Course Notes
Verified Note
1 document

Document Summary

Csc148: lecture 17: nested recursion and recursion functions. References: pictures seen in the code can be found on the csc148 website: http://www. cdf. utoronto. ca/~csc148h/winter. To concatenate strings in a nested list if istinstance(string_list, list): general case. Can write concat_strings in a different way: use list comprehension. if else Expression 1 evaluated if condition is true. Expession 2 evaluated if condition is false. Use functional if to write function sum([flatten(x) if isinstance(x, list) else [x] for x in list_], []: functional if, can write functional if on multiple lines for better spacing and readability. Instead of using a functional if, can also use an if statement to write this code. Returns whether list_ for any nested sub-list in list_ contains a value. Recursion when input is a recursive structure. If input can"t be decomposed into recursive sub-structures, you have a base case you can directly return result with recursion.

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 Questions