----------------- A List is a sequence [10, 20, 30, 40] ['I School U', 'UC Berkeley', 'Ariel Chait'] Lists can contain Multiple types and nested lists ['facebook', 2.0, 5, [10,20]] ----------------- ----------------- You can assign a list to a variable! >>> cheeses = ['Cheddar', 'Jack', 'Gouda'] >>> numbers = [12, 123] >>> empty = [] >>> print(cheeses) ['Cheddar', 'Jack', 'Gouda'] ----------------- ----------------- We use Brackets with indices to access elements in the list >>> cheeses[0] 'Cheddar' ----------------- ----------------- A list is a relationship between indices and elements called a mapping Cheeses 0 -> 'Cheddar' 1 -> 'Jack' 2 -> 'Gouda' ----------------- ----------------- Traversing a list for cheese in cheese: print(cheese) for i in range(len(cheeses)): print(cheeses[i]) ----------------- ----------------- List Methods >>> myList = ['a', 'b', 'c'] >>> myList.append('d') >>> print(myList) >>> ['a','b','c','d'] >>> myList = ['d','a','c','b'] >>> myList.sort() >>> print(myList) >>> ['a','b','c','d'] ----------------- ----------------- Python provides us with a function called sum() sum() can add up any number of elements or even a list >>> t = [1, 2, 3] >>> sum(t) 6 ----------------- ----------------- Strings are lists of sorts >>> myString = "Hello World" >>> myString[1] >>> e Slicing [start:stop:step] >>> myString[0:2] >>> "He" >>> myString[2:0:-1] >>> >>> myString[::-1] >>> 'dlroW olleH' ----------------- ----------------- Exercise -----------------