<jupyter_start><jupyter_text>In-Class Coding Lab: ListsThe goals of this lab are to help you understand: - List indexing and slicing - List methods such as insert, append, find, delete - How to iterate over lists with loops  Python Lists work like Real-Life Lists In real life, we make lists all the time. To-Do lists. Shopping lists. Reading lists.  These lists are collections of items, for example here's my shopping list:  ``` Milk, Eggs, Bread, Beer ```There are 4 items in this list.Likewise, we can make a similar list in Python, and count the number of items in the list using the `len()` function:<jupyter_code>shopping_list = [ 'Milk', 'Eggs', 'Bread', 'Beer']
item_count = len(shopping_list)
print("List: %s has %d items" % (shopping_list, item_count))<jupyter_output>List: ['Milk', 'Eggs', 'Bread', 'Beer'] has 4 items<jupyter_text>Enumerating Your List ItemsIn real-life, we *enumerate* lists all the time. We go through the items on our list one at a time and make a decision, for example: "Did I add that to my shopping cart yet?"In Python we go through items in our lists with the `for` loop. We use `for` because the number of items is pre-determined and thus a **definite** loop is the appropriate choice. Here's an example:<jupyter_code>for item in shopping_list:
    print("I need to buy some %s " % (item))
# or with f-strings
for item in shopping_list:
    print(f"I need to buy some {item}")<jupyter_output><empty_output><jupyter_text>Now You Try It!Write code in the space below to print each stock on its own line.<jupyter_code>stock_list = [ 'IBM', 'AAPL', 'GOOG', 'MSFT', 'TWTR', 'FB']
#TODO: Write code here
len(stock_list)
for stock in stock_list:
    print("I can invest in %s" %(stock))<jupyter_output>I can invest in IBM
I can invest in AAPL
I can invest in GOOG
I can invest in MSFT
I can invest in TWTR
I can invest in FB<jupyter_text>Indexing ListsSometimes we refer to our items by their place in the list. For example "Milk is the first item on the list" or "Beer is the last item on the list."We can also do this in Python, and it is called *indexing* the list. **IMPORTANT** The first item in a Python lists starts at index **0**.<jupyter_code>print("The first item in the list is:", shopping_list[0]) 
print("The last item in the list is:", shopping_list[3])   
print("This is also the last item in the list:", shopping_list[-1])  
print("This is the second to last item in the list:", shopping_list[-2])<jupyter_output>The first item in the list is: Milk
The last item in the list is: Beer
This is also the last item in the list: Beer
This is the second to last item in the list: Bread<jupyter_text>For Loop with IndexYou can also loop through your Python list using an index. In this case we use the `range()` function to determine how many times we should loop:<jupyter_code>for i in range(len(shopping_list)):
    print("I need to buy some %s " % (shopping_list[i]))<jupyter_output>I need to buy some Milk 
I need to buy some Eggs 
I need to buy some Bread 
I need to buy some Beer<jupyter_text>Now You Try It!Write code to print the 2nd and 4th stocks in the list variable `stocks`. For example:`AAPL MSFT`<jupyter_code>#TODO: Write code here
print("the second stock in the list is:", stock_list[1])
print("the fourth stock in the list is:", stock_list[3])<jupyter_output>the second stock in the list is: AAPL
the fourth stock in the list is: MSFT<jupyter_text>Lists are MutableUnlike strings, lists are mutable. This means we can change a value in the list.For example, I want `'Craft Beer'` not just `'Beer'`:<jupyter_code>print(shopping_list)
shopping_list[-1] = 'Craft Beer'
print(shopping_list)<jupyter_output>['Milk', 'Eggs', 'Bread', 'Beer']
['Milk', 'Eggs', 'Bread', 'Craft Beer']<jupyter_text>List MethodsIn your readings and class lecture, you encountered some list methods. These allow us to maniupulate the list by adding or removing items.<jupyter_code>print("Shopping List: %s" %(shopping_list))

print("Adding 'Cheese' to the end of the list...")
shopping_list.append('Cheese')  #add to end of list
print("Shopping List: %s" %(shopping_list))

print("Adding 'Cereal' to position 0  in the list...")
shopping_list.insert(0,'Cereal') # add to the beginning of the list (position 0)
print("Shopping List: %s" %(shopping_list))

print("Removing 'Cheese' from the list...")
shopping_list.remove('Cheese')  # remove 'Cheese' from the list
print("Shopping List: %s" %(shopping_list))

print("Removing item from position 0 in the list...")
del shopping_list[0]   # remove item at position 0
print("Shopping List: %s" %(shopping_list))<jupyter_output>Shopping List: ['Milk', 'Eggs', 'Bread', 'Craft Beer']
Adding 'Cheese' to the end of the list...
Shopping List: ['Milk', 'Eggs', 'Bread', 'Craft Beer', 'Cheese']
Adding 'Cereal' to position 0  in the list...
Shopping List: ['Cereal', 'Milk', 'Eggs', 'Bread', 'Craft Beer', 'Cheese']
Removing 'Cheese' from the list...
Shopping List: ['Cereal', 'Milk', 'Eggs', 'Bread', 'Craft Beer']
Removing item from position 0 in the list...
Shopping List: ['Milk', 'Eggs', 'Bread', 'Craft Beer']<jupyter_text>Now You Try It!Write a program to remove the following stocks: `IBM` and `TWTR`Then add this stock to the end `NFLX` and this stock to the beginning `TSLA`Print your list when you are done. It should look like this:`['TSLA', 'AAPL', 'GOOG', 'MSFT', 'FB', 'NFLX']`<jupyter_code># TODO: Write Code here
print("stocks you can invest in:%s"%(stock_list))

print("removing IBM from list...")
stock_list.remove("IBM")
print("shopping list:%s"%(stock_list))

print("removing TWTR from list...")
stock_list.remove("TWTR")
print("shopping list:%s"%(stock_list))

print("adding NFLX to position 5...")
stock_list.insert(5,"NFLX")
print("shopping list:%s"%(stock_list))

print("moving TSLA to position 0...")
stock_list.insert(0,"TSLA")
print("shopping list:%s"%(stock_list))<jupyter_output>stocks you can invest in:['IBM', 'AAPL', 'GOOG', 'MSFT', 'TWTR', 'FB']
removing IBM from list...
shopping list:['AAPL', 'GOOG', 'MSFT', 'TWTR', 'FB']
removing TWTR from list...
shopping list:['AAPL', 'GOOG', 'MSFT', 'FB']
adding NFLX to position 5...
shopping list:['AAPL', 'GOOG', 'MSFT', 'FB', 'NFLX']
moving TSLA to position 0...
shopping list:['TSLA', 'AAPL', 'GOOG', 'MSFT', 'FB', 'NFLX']<jupyter_text>SortingSince Lists are mutable. You can use the `sort()` method to re-arrange the items in the list alphabetically (or numerically if it's a list of numbers)<jupyter_code>print("Before Sort:", shopping_list)
shopping_list.sort() 
print("After Sort:", shopping_list)<jupyter_output>Before Sort: ['Milk', 'Eggs', 'Bread', 'Craft Beer']
After Sort: ['Bread', 'Craft Beer', 'Eggs', 'Milk']<jupyter_text>Putting it all togetherWinning Lotto numbers. When the lotto numbers are drawn, they are in any order, when they are presented they're allways sorted. Let's write a program to input 5 numbers then output them sorted```1. for i in range(5)2.    input a number3.    append the number you input to the lotto_numbers list4. sort the lotto_numbers list5. print the lotto_numbers list like this:    'today's winning numbers are [1, 5, 17, 34, 56]'```<jupyter_code>## TODO: Write program here:
lotto_numbers = []
for i in range(5):
    num=int(input("enter the next winning number:"))
    lotto_numbers.append(num)
lotto_numbers.sort()
print("Tonights winning numbers are %s"%(lotto_numbers))<jupyter_output>enter the next winning number:1
enter the next winning number:3
enter the next winning number:5
enter the next winning number:7
enter the next winning number:9
Tonights winning numbers are [1, 3, 5, 7, 9]<jupyter_text>MetacognitionPlease answer the following questions. This should be a personal narrative, in your own voice. Answer the questions by double clicking on the question and placing your answer next to the Answer: prompt.1. Record any questions you have about this lab that you would like to ask in recitation. It is expected you will have questions if you did not complete the code sections correctly.  Learning how to articulate what you do not understand is an important skill of critical thinking. Answer: My question for this lab is about when sorting a list of numbers, why does it reject the sort command even when you set the input as an integer? is there something that can be done to bypass this?2. What was the most difficult aspect of completing this lab? Least difficult?  Answer: The most difficult part of this lab was putting it all together. The instruction sometimes stumps me because I am someone who must have a very clear set of instructions when putting it all together. I'm not sure if theres something I have missed but I am reviewing to see what I might not be understanding.3. What aspects of this lab do you find most valuable? Least valuable?Answer: This lab is very valuable overall because the use of lists saves us from having to write out much longer, aggravating algorithms. It teaches us a simplified way of handling lists which is a great tool to have.4. Rate your comfort level with this week's material so far.   1 ==> I can do this on my own and explain how to do it.   2 ==> I can do this on my own without any help.   3 ==> I can do this with help or guidance from others. If you choose this level please list those who helped you.   4 ==> I don't understand this at all yet and need extra help. If you choose this please try to articulate that which you do not understand.   Answer: I am going to put myself at a 2 for this one only because I had toruble when it came to putting it all together.<jupyter_code># to save and turn in your work, execute this cell. Your latest submission will be graded. 
ok.submit()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1040289256198347, 'fraction_numerical': 0.006301652892561983, 'mean_word_length': 5.005583126550868, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '640450', 'license': 'MIT', 'n_tokens_mistral': 3083, 'n_tokens_neox': 2991, 'n_words': 1389, 'path': 'content/lessons/08/Class-Coding-Lab/CCL-Lists.ipynb', 'repo_name': 'MahopacHS/spring-2020-neubauerc', 'size': '9680'}