<jupyter_start><jupyter_text>Lists, dictionaries and comprehension **A list in python according to python itself is:**  *A built-in Python sequence. Despite its name it is more akin to an array in other languages than to a linked list since access to elements is O(1).*  reference: https://docs.python.org/3/glossary.htmlBut a more accurate definition would be:  *A list is a data structure in Python that is a mutable, or changeable, ordered sequence of elements. Each element or value that is inside of a list is called an item. Just as strings are defined as characters between quotes, lists are defined by having values between square brackets [ ].*  reference: https://www.digitalocean.com/community/tutorials/understanding-lists-in-python-3 ___  **A dicionary in python according to python itself is:**  *An associative array, where arbitrary keys are mapped to values. The keys can be any object with __hash__() and __eq__() methods. Called a hash in Perl.*  reference: https://docs.python.org/3/glossary.htmlBut a more accurate definition would be:  *A dictionary is a collection which is ordered, changeable and do not allow duplicates.*  reference: https://www.w3schools.com/python/python_dictionaries.asp ___Format for list and dictionary<jupyter_code>list1 = [item1,item2,item3]
dictionary1 = {item1,item2,item3}<jupyter_output><empty_output><jupyter_text>list having dictionaries, and dictionaries having lists<jupyter_code>list1 = [
    dict_1 = {item1,item2,item3},
    dict_2 = {item1,item2,item3},
    dict_3 = {item1,item2,item3}
]

dictionary1 = {
    list_1 = [item1,item2,item3],
    list_2 = [item1,item2,item3],
    list_3 = [item1,item2,item3]
}<jupyter_output><empty_output><jupyter_text>Examples with dictionary containing lists<jupyter_code>def run():
   dict = {
       "prime_numbers": [1,2,3,5,7],
       "natural_numbers": [10,15,16,77],
       "float_numbers": [15.5,9.8,3.14]
   }

   for key, value in dict.items():
       print(key, "-", value)


if __name__ == "__main__":
    run()<jupyter_output><empty_output><jupyter_text>Example of list containing dictionaries<jupyter_code>def run():
    list1 = [
        {"firstname": "Russel", "lastname": "Wallace"},
        {"firstname": "Charles", "lastname": "Darwin"},
        {"firstname": "Gregor", "lastname": "Mendel"}
    ]

    print(list1)

if __name__ == "main":
    run()
group_1 = [169,177,174,170,177]
group_2 = [186,168,167,189,179]
group_3 = [171,175,172,180,191]
    
mean_group_1 = statistics.mean(group_1)
mean_group_2 = statistics.mean(group_2)
mean_group_3 = statistics.mean(group_3)

print("group 1 mean is", mean_group_1,"group 2 mean is", mean_group_2, "group 3 mean is", mean_group_3)<jupyter_output><empty_output><jupyter_text>Printing the square of the the first 100 numbers<jupyter_code>squares = []
for i in range(1,101):
    if i % 3 == 0:
        squares.append(i**2)
        
print(squares)<jupyter_output><empty_output><jupyter_text>--- List and Dictionary ComprehensionAccording to Python Documentation:  List comprehensions provide a concise way to create lists. Common applications are to make **new lists where each element is the result of some operations applied to each member of another sequence** or iterable, or to create a subsequence of those elements that satisfy a certain condition.  References: https://docs.python.org/3/tutorial/datastructures.htmllist-comprehensionsExample<jupyter_code>squares = [i for i in range(1,10000) if i % 36 == 0]
print(squares)<jupyter_output><empty_output><jupyter_text>Next, code for dictionary, and dictionary comprehension<jupyter_code>cubes = {}
for i in range(101):
        if i % 3 != 0:
            cubes[i] = i**3

print(cubes)<jupyter_output><empty_output><jupyter_text>Examples of dictionary comprehension<jupyter_code>cubes = {i: i**3 for i in range(101) if i % 3 != 0}
print(cubes)
    
cubes = {i:round(i**0.5,2) for i in range(1001)}
print(cubes)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11496581413015954, 'fraction_numerical': 0.0407698151430742, 'mean_word_length': 4.895522388059701, 'pattern_counts': {'":': 11, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 5, 'lorem ipsum': 0, 'www.': 2, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '654521', 'license': 'Apache-2.0', 'n_tokens_mistral': 1406, 'n_tokens_neox': 1284, 'n_words': 382, 'path': 'python_projects/intermidiate_python/list_dictionaries_comprehension.ipynb', 'repo_name': 'DavGarza/Learning-data-science', 'size': '3949'}