# Chapter6.py ''' data bit 0/1 byte 01000001 'A' char 'A' 'n' 'd' 'y' string Andy number / bool / datetime / complex / float ... [a-zA-Z0-9][specials] collection class Bob Joe Mary 21 True 12/24/2024 bunch of values Lists [] index[0] dups mutatable Level 1 Sets {} collection of values without duplicates Level 2 Tuples () posid[0] param[1] dups readOnly immutable Level 1 Dictionary/Maps { key: value } { fname: Bob, lname: Bob } key!dup:valuedup valueUpdated Level 2 dimensional data Level 3 1 Dimensional Series -> col -> 2 Dimensional DataFrame -> x/y row/col -> 3 Dimensional aka PivotTable/Chart -> P1 row/col -> 4 Dim P2 P1 -> row/col -> ... 7 Dim P5 P4 P3 P2 row/col -> ''' # Lists [] page 164 and Tuples () page 194 # Bob, Joe, Mary, Beth firstName_list = ["Bob", "Joe", "Mary", "Beth"] firstName_tuple = ("Bob", "Joe", "Mary", "Beth") ## Best Practices for Lists ## Create an EMPTY list object, then populate it with value ## 2 methods for updating data ### 1. use the insert() function then assign value ### 2. Preferred Best Practice -> use the index id to update the value firstName_list[0] = "Robert" ## use the for x in ys loop to loop thru list data "for loop" ## Nesting Lists ### [ [ ], [ ] ] List[List] Best Practice ### { [ ], [ ] } optional List Set # Lists can contain DISSIMILAR data types # ["Bob", 21, True ] [string, int, boolean] # Add a contact to a master contacts list contact = [] # Create an empty list object and store in memory contact.append('Bob') # ['Bob'] contact.append(21) # ['Bob', 21 ] contact.append(True) # ['Bob',21,True] print(contact) contacts = [] contacts.append(contact) print(contacts) # [['Bob', 21, True]] # Add a second contact to contacts contact = [] # Create an empty list object and store in memory contact.append('Mary') contact.append(24) contact.append(False) print(contact) # ['Mary',24,False] contacts.append(contact) print(contacts) # [['Bob', 21, True], ['Mary', 24, False]] # How do we access the individual objects in the loop ## for loop ## for x in ys ### x is the name of the variable in the subop/scope ### ys is where the data is coming from for first_name in firstName_list: print(first_name) # Bob value without the ' ' # firstName_list = ["Bob", "Joe", "Mary", "Beth"] # step 1 for loop gets the len(firstName_list) of ys -> 4 # l = len(firstName_list) -> 4 # step 2 create a control variable for the index # let i = 0 ## subop1 print(firstName_list[i]) i = 0 -> Bob # step 3 i += 1 (increment i) i = 1 # step 4 while i < len(firstName_list) is 1 < 4 True -> continue # i = 1 -> Joe -> i + 1 -> i = 2 # while 2 < 4 -> continue -> Mary # while 3 < 4 -> continue -> Beth # while 4 < 4 -> False -> break for loop