<jupyter_start><jupyter_text>TuplesTuples are like lists, but are *immutable*, meaning that once you've made them they can't be changed.   Predict what this code will do.<jupyter_code>some_tuple = (10,20,30)
print(some_tuple[1])
some_tuple = (10,20,30)
print(some_tuple[:])<jupyter_output>(10, 20, 30)<jupyter_text>Predict what this code will do.<jupyter_code>some_tuple = (10,20,30)
some_tuple[1] = 50
some_tuple = (10,20,30)
some_tuple.append(10)<jupyter_output><empty_output><jupyter_text>SummarizeHow are tuples like lists?  How are they different? + You access values like lists+ You can't tuples once they've been created Geeky note: tuples are useful because they are "hashable" and can be used as keys for dictionaries, while lists are not hashable and can't be dictionary keys.  StringsStrings hold text.  They are actually tuple-like under the hood.   Predict what this code will do.<jupyter_code>a_string = "This is a string"
print(a_string[0])
print(a_string[5:])
print(a_string[:-1])<jupyter_output>T
is a string
Thisxis a strin<jupyter_text>Predict what this code will do.<jupyter_code>a_string = "This is a string"
a_string[0] = "a"<jupyter_output><empty_output><jupyter_text>SummarizeHow are strings like lists?  How are they different? + You access values like lists+ You can't change elements individually.  If you want to modify a string, convert it to a list of letters first.<jupyter_code>a_string = "This is a string"
print(a_string)

#Convert the string to a list
a_list = list(a_string)
print(a_list)

# Set the first element in the list to "a"
a_list[0] = "a"

# Convert the list back to a string
a_string = ",".join(a_list)
print(a_string)<jupyter_output>This is a string
['T', 'h', 'i', 's', ' ', 'i', 's', ' ', 'a', ' ', 's', 't', 'r', 'i', 'n', 'g']
a,h,i,s, ,i,s, ,a, ,s,t,r,i,n,g<jupyter_text>DictionariesDictionaries map `keys` to `values`.  The `keys` and `values` can be almost anything.   Predict what this code will do.<jupyter_code>some_dict = {"a":10,
             "b":20,
             "c":30}
print(some_dict["a"])
print(some_dict["b"])
another_dict = {1:10,
                "test":print,
                1.5:-10,
                (1,2,3):"cow"}
print(another_dict["test"])
print(another_dict[(1,2,3)])<jupyter_output><built-in function print>
cow<jupyter_text>Predict what this code will do.<jupyter_code>some_dict = {"a":10,
             "a":20,
             "c":10}
some_dict["a"] = [1,2,3]<jupyter_output><empty_output><jupyter_text>SummarizeHow do you access elements in a dictionary? + You access "values" in a dictionary using "keys".  + This only works one-way: keys map to values, values do not map to keys  Predict what this code will do.<jupyter_code>some_dict = {"a":10,"b":20,"c":30}
for k in some_dict.keys():
    print(k,some_dict[k])
    
some_dict = {"a":10,"b":20,"c":30}    
for v in some_dict.values():
    print(v)
another_dict = dict([(some_dict[k],k) for k in some_dict.keys()])
another_dict[10]<jupyter_output><empty_output><jupyter_text>SummarizeWhat do `keys()` and `values()` do? + These provide access to all of the keys and values in a dictionary.+ These are `iterators` (like `range`) that can be looped through with `for`.  Predict what this code will do.<jupyter_code>some_dict = {"a":10,"b":20,"c":30}
some_dict["c"] = 50
print(some_dict)
some_dict = {"a":10,"b":20,"c":30}
some_dict["d"] = 50
print(some_dict)<jupyter_output>{'a': 10, 'b': 20, 'c': 30, 'd': 50}<jupyter_text>SummarizeHow do you set values in the dictionary? `SOME_DICTIONARY[KEY] = VALUE`  Predict what this code will do.<jupyter_code>some_dict = {"a":10,"b":20,"c":30}
x = some_dict.pop("a")
print(x)
print(some_dict)<jupyter_output>10
{'b': 20, 'c': 30}<jupyter_text>SummarizeHow do you remove a key-value pair from a dictionary?<jupyter_code>VALUE = SOME_DICT.pop(KEY)<jupyter_output><empty_output><jupyter_text>ImplementCreate a dictionary that lets you look up each species by its color. | species | color      | |---------|------------|| cow     | brown      || pig     | pink       || salmon  | silver     || squid   | it decides |<jupyter_code>look_up = {"brown":"cow",
           "pink":"pig",
           "salmon":"silver",
           "it decides":"squid"}<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15092111478507322, 'fraction_numerical': 0.028105810108644307, 'mean_word_length': 4.746268656716418, 'pattern_counts': {'":': 26, '<': 44, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '556418', 'license': 'Unlicense', 'n_tokens_mistral': 1623, 'n_tokens_neox': 1531, 'n_words': 429, 'path': 'chapters/00_inductive-python/key/07_tuples-and-dicts-and-strings_key.ipynb', 'repo_name': 'lperezmo/pythonic-science', 'size': '4234'}