CMPT 120 Lecture : Lists

54 views2 pages
meghan78 and 39786 others unlocked
CMPT 120 Full Course Notes
29
CMPT 120 Full Course Notes
Verified Note
29 documents

Document Summary

=> 20 for i in range(len(mylist)): print mylist[i] lists can hold any type of data words = [ apple , pear , bananas ] junk = [1, two , [1,1,1], true] print junk[2][1] => 1 lists can be created by functions or methods. => [0, 1, 2, 3] range(4) s = one two three print s. split( ) lists can be joined like strings. => [ one , two , three ] print [0, 1] + [20, 30] lists can be modified without totally rebuilding them. => [0, 1, 20, 30] mylist = [0, 10, 20, 30] mylist. append( 40) print mylist. => [0, 10, 20, 30, 40] mylist. append(-50) mylist. sort() print mylist the append and sort methods don"t return anything, they change the list in- place. A lot of work: lst. append(x) changes the existing list. Much less work: eg. get some numbers from the user and display num = int(raw_input( how many? )) values = [] for i in range(num):

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

Related Questions