CSE 1000 Lecture 5: Lists

23 views2 pages

Document Summary

List a sequence of comma-separated values between square brackets. Like strings, lists can be indexed or sliced: squares [0] Squares [-3:] (start at -3 and go to the end of the line, aka last 3 numbers in line) The items in a list need not be of the same type: list = ["physics", "chemistry", 1997, 2000] Updating lists - changing value of list. Deleting list elements: del list [2] List buildup: append always goes to end of the list. Cannot work with numbers, numbers have to be in a list: list. insert(0, "x") insert method inserts element into list before the index. Index method returns the lowest index in list that element appears: list. index("b") Remove method removes element from list (removes first appearance of element in list if it is repeated: list. remove("b", list. ["x", "a", "b", "c": del uses an index number, so if you want to delete a second occurance use del instead of remove.

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