''' Purpose: introduce lists ''' # this is being created on the flyyyyyyy reply = input('Enter a line of text: ') # if we respond with Wubba lubba dub dub! # split reply into individual words...but we don't know how many words are being entered!!!! # how do??? words = reply.split() # ignores leading and trailing whitespace # officially, split returns a list print(reply) # reply is the string 'Wubba lubba dub dub!' print(words) # words is a list ['Wubba', 'lubba', 'dub', 'dub!'] # [] is the empty list # Enter a line of text: 1 3 5 7 9 # 1 3 5 7 9 # ['1', '3', '5', '7', '9'] this is a list of STRINGS for w in words: # words is a sequence; w in words represents each element in the list words # w is the iterator; each time the loop repeats, w changes because we are going through each element in the list print( ' ', w ) # for word in words: # print(word) reply2 = input('Enter a list of numbers: ') numbers = reply2.split() # we want to convert each number in numbers into a int # numbers = int(numbers) # numbers is a list...a list is not a single value, but a SEQUENCE of values # print(numbers) n = len(numbers) # the number of elements in numbers for i in range(0, n): nbr = numbers[i] # numbers[i] takes the value from that index, i, of the list numbers nbr = int(nbr) # nbr points to the same value as numbers[i], so we are converting (casting) nbr to an int numbers[i] = nbr # the int version of nbr is being inserted back into the original list in the same index (spot) print(numbers) # no quotes around each number, so that means each element is an int