<jupyter_start><jupyter_text>Module 2.5 Lists, SummarizedCreated By: <NAME>Each code block is designed to be an independent program for ease of use!---***Disclaimer***> Copyright (c) 2020 <NAME>> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  Part 1: Declaring ListsIn Python, lists are easily declared using brackets `[]`Lists contain an ordered set of data points! These can include numbers, strings, boolean values, and even another list!  Declaring Simple List<jupyter_code>simple_list = [0, 1, 2, 3, 4]
print(simple_list)<jupyter_output>[0, 1, 2, 3, 4]<jupyter_text>Declaring Complex List<jupyter_code>complex_list = [[1,2,3],[4,5,6],[7,8,9]]
print(complex_list)<jupyter_output>[[1, 2, 3], [4, 5, 6], [7, 8, 9]]<jupyter_text>Part 2: Indexing ListsUsing the general notation `list[n]` we can access elements at a specific position!Remember, Python is zero-indexed, so the first element has a positional value of `0`   Accessing List Element with Index<jupyter_code>simple_list = [0, 1, 2, 3, 4]

print(simple_list[2])
print(simple_list[4])<jupyter_output>2
4<jupyter_text>Updating List Element by Index<jupyter_code>simple_list = [0, 1, 2, 3, 4]
simple_list[2] = "Dog"

print(simple_list)<jupyter_output>[0, 1, 'Dog', 3, 4]<jupyter_text>Accessing List Element with Negative IndexIn Python, we can easily access the end of the list by providing a negative index! `-1` is always the last element in a list!<jupyter_code>simple_list = [0, 1, 2, 3, 4]

print(simple_list[-1])
print(simple_list[-3])<jupyter_output>4
2<jupyter_text>Accessing a Range of Elements via IndexIn Python, easily access a range of elements with the general argument `list[n:m]`Python will select everything from the argument `n` up to, *but not including*, argument `m`!<jupyter_code>simple_list = [0, 1, 2, 3, 4]

print(simple_list[2:4])<jupyter_output>[2, 3]<jupyter_text>Range with Negative IndexPython will still select left to right, but can also start at a negative index!<jupyter_code>simple_list = [0, 1, 2, 3, 4]

print(simple_list[-4:-1])<jupyter_output>[1, 2, 3]<jupyter_text>Part 3: Common List Methods| Method | Description || --- | --- || `.append()` | Adds argument to end of list || `.pop()` | Removes (and optionally returns) last element of list || `.insert()` | Adds argument to list at specific index || `.remove()` | Removes specific element from list || `.clear()` | Empties entire list || `.sort()` | Sorts list in ascending order || `.reverse()` | Reverses order of list |  Add To End of List with `.append()`<jupyter_code>my_list = [1,3,5,7,9]
my_list.append(11)

print(my_list)<jupyter_output>[1, 3, 5, 7, 9, 11]<jupyter_text>Remove Last Element with `.pop()`<jupyter_code>my_list = [1,3,5,7,9]
my_list.pop()

print(my_list)<jupyter_output>[1, 3, 5, 7]<jupyter_text>Add Element at Specific Position with `.insert()`Follows general syntax `list.insert(index, value)`<jupyter_code>my_list = [1,3,5,7,9]
my_list.insert(2,4)

print(my_list)<jupyter_output>[1, 3, 4, 5, 7, 9]<jupyter_text>Remove Specific Element with `.remove()`Removes first instance of argument provided from list.<jupyter_code>my_list = [1,3,5,7,9]
my_list.remove(3)

print(my_list)<jupyter_output>[1, 5, 7, 3, 9]<jupyter_text>Empty List with `.clear()`<jupyter_code>my_list = [1,3,5,7,9]
my_list.clear()

print(my_list)<jupyter_output>[]<jupyter_text>Sort List in Ascending Order with `.sort()`<jupyter_code>my_list = [5,3,7,1,9]
my_list.sort()

print(my_list)<jupyter_output>[1, 3, 5, 7, 9]<jupyter_text>Sort List in Descending Order with `.sort()`<jupyter_code>my_list = [1,3,5,7,9]
my_list.sort(reverse=True)

print(my_list)<jupyter_output>[9, 7, 5, 3, 1]<jupyter_text>Reverse Order of List with `.reverse()`<jupyter_code>my_list = [1,3,5,7,9]
my_list.reverse()

print(my_list)<jupyter_output>[9, 7, 5, 3, 1]
{'fraction_non_alphanumeric': 0.12429022082018927, 'fraction_numerical': 0.03533123028391167, 'mean_word_length': 6.283307810107198, 'pattern_counts': {'":': 0, '<': 48, '<?xml version=': 0, '>': 52, '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': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '393540', 'license': 'MIT', 'n_tokens_mistral': 1765, 'n_tokens_neox': 1614, 'n_words': 554, 'path': 'modules/module-02/module2-lists.ipynb', 'repo_name': 'mhall-simon/python', 'size': '4767'}