<jupyter_start><jupyter_text>Python fundamentals, part 2Importing modules, indentation, `if` statements, `for` loops.  Importing modulesYou can import modules into your script -- snippets of Python code that give you access to additional functionality or variables -- from:- the [Python standard library](https://docs.python.org/3/library/index.html), which is part of the Python installation package- from your own Python files- and from third-party developers using a tool called [`pip`](https://docs.python.org/3/installing/index.html).A collection of modules is usually referred to as a "package" or "library."For this class, we've pre-installed five external libraries: `jupyter`, `bs4`, `requests`, `matplotlib` and `geopy`.<jupyter_code># import the csv module from the Python standard library
# https://docs.python.org/3/library/csv.html


# import the BeautifulSoup class from the (external) bs4 package


# import variables from a local file, my_module.py
# alias to `mm` using the `as` keyword


# access bits of the module with a period .<jupyter_output><empty_output><jupyter_text>IndentationWhitespace matters in Python. Sometimes you'll need to indent bits of code to make things work. This can be confusing! (FWIW, Jupyter will try to be helpful and insert the correct amount of "significant whitespace" for you.) You can use tabs or spaces, just don't mix them. [The Python style guide](https://www.python.org/dev/peps/pep-0008/) recommends indenting your code in groups of four spaces, so that's what we'll use today.  `if` statementsJust like in Excel, you can use the "if" keyword to handle conditional logic.These statements begin with the key word `if` (lowercase), then the condition to evaluate, then a colon, then a new line with a block of indented code to execute if the condition resolves to `True`. You can also add an `else` statement (and a colon) with an indented block of code you want to run if the condition resolves to `False`. If you need to, you can add multiple conditions with `elif`.  `for` loopsUse a `for` loop to iterate over a collection of things. The statement begins with the keyword `for` (lowercase) `variable_name` `in` `collection_to_iterate`, then a colon, then the indented block of code with instructions about what to do with each item in the collection.<jupyter_code># let's import a list of ingredients for pico de gallo


# print the list to see what's there


# now use a `for` loop to iterate over the list and print each item
# ("ingredient" is an arbitrary variable name)


# you can also iterate over a dictionary

# let's import our puppy


# the iterable element in a dictionary is the key
# so I like to use that as my variable
# --> remember! order is not guaranteed in a dict

# lots of things are iterable -- you can even loop over the characters in a string!<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07520111927247289, 'fraction_numerical': 0.003497726477789437, 'mean_word_length': 4.618860510805501, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 4, 'lorem ipsum': 0, 'www.': 1, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '661331', 'license': 'MIT', 'n_tokens_mistral': 790, 'n_tokens_neox': 752, 'n_words': 409, 'path': 'exercises/01. Python Fundamentals (Part 2)-working.ipynb', 'repo_name': 'cjwinchester/cfj-2017', 'size': '2859'}