CSC148H5 Lecture Notes - Lecture 9: University Of Toronto Mississauga, Newline

46 views4 pages

Document Summary

Csc148h5s - introduction to computer science (winter 2017) # part e try : except nameerror: division(x, 1 ) print( "name not defined outside" ) The steps through the (like a for-loop) For each value of , is evaluated and added to a running list. >>> [x + 5 for x in lst] >>> lst = [x + 5 for x in lst] Suppose we have a list of lines that each end with a newline. Create a new list of the same elements but without the new lines. >>> lst = [ " abc " , "def\n" , "ghi\n\n" ] Combine the first elements of each iterable, second elements of each iterable etc. >>> for pair in zip([ 1 , 2 ], [ 3 , 4 ]): Here zip creates a list of tuples, and the comprehension multiplies corresponding elements. >>> [a * b for a, b in zip(x, y)]

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