1. Create manually:

    1. An empty dictionary. Check whether the dictionary is empty with len().

    2. A dictionary pronouns representing these correspondences:

      1 -> "me"
      2 -> "you"
      3 -> "he"

      Create the dictionary in 2 ways:

      1. In a single line of code.
      2. Starting from an empty dictionary and adding one by one single key value pairs.
    3. A dictionary tenfold_of implementing the function \(f(n) = 10 n\), matching each key (an integer) with its tenfold.

      Keys should be integers from 1 to 5.

      Once the dictionary is built, apply it to all the elements of range(2, 5) with a list comprehension and print to screen the result.

      Repeat the same for all the keys of tenfold_of.

      Hint: you can obtain the list of all keys with keys().

    4. A dictionary info_2TMV codifying structured information about the PDB entry 2TMV containing the structure of a capsid protein of the Tobacco Mosaic Virus.

      1. To the key "pdb_id" associate the value "2TMV".
      2. To the key "uniprot_id" associate the value "P69687 (CAPSD_TMV)".
      3. To the key "number_scp_domains" associate 1.
      4. To the key "number_pfam_domains" associate 1.
    5. A dictionary relatives_of representing this network:

        |                       |
        + ----- BENEDICT -------+

      as in the example we saw before.

      Once the dictionary is built, print to screen the number of relatives of "JULIE".

    6. A dictionary from_2_bit_to_integer representing the map from the following pairs of integers to integer:

      0, 0 -> 0                           # 0*2**1 + 0*2**0 = 0
      0, 1 -> 1                           # 0*2**1 + 1*2**0 = 1
      1, 0 -> 2                           # 1*2**1 + 0*2**0 = 2
      1, 1 -> 3                           # 1*2**1 + 1*2**1 = 3
      ^^^^    ^                             ^^^^^^^^^^^^^^^^^^^
      key  value                            explanation

      Once the dictionary is built, pront to screen the value associated with one of the keys (choose arbitrarily).

  2. Given:

    ratios = {
        ("A", "T"): 10.0 / 5.0,
        ("A", "C"): 10.0 / 7.0,
        ("A", "G"): 10.0 / 6.0,
        ("T", "C"): 5.0 / 7.0,
        ("T", "G"): 5.0 / 6.0,
        ("C", "G"): 7.0 / 6.0,

    representing ratios between the number of A, T, C, e G in a sequence:

    1. What is the difference between len(ratios), len(ratios.keys()), len(ratios.values()) e len(ratios.items())?

    2. Check whether ratios contains the key ("T", "A"). And the key ("C", "G")?

      Hint: can we use keys()? Can we use another method?

    3. Check whether it contains the value 2. And the value 3?

      Hint: can we use values()?

    4. Check whether it contains the key-value pair (("A", "T"), 2). And the key-value pair (("C", "G"), 1000)?

      Hint: can we use items()?

    5. Use a list comprehension to extract the keys of the result of items(). Do the same to extract values.

  3. Given:

    map = {
        "zero": 1,
        "one": 2,
        "two": 4,
        "three": 8,
        "four": 16,
        "five": 32,
    1. Concatenate all the keys map, separated by spaces, in a single string string_of_keys.

    2. Concatenate all the values of map as strings, separated by spaces, in a single string string_of_values.

      Hint: note that the values of map are not strings!

    3. Insert in a list all the keys of map.

    4. Insert in a list all the keys of map, ordered alphanumerically.

      Hint: is the list returned by keys() ordered?

    5. Insert in a list all the values of map, ordered according to the order of the corresponding keys.

      Hint: how can I order a list based on the order of another list?

  4. Given:

    translation_of = {"a": "ade", "c": "cyt", "g": "gua", "t": "tym"}

    translate the list:

    list = ["A", "T", "T", "A", "G", "T", "C"]

    into the string:

    "ade tym tym ade gua tym cyt"

    Hint: note that dictionary keys are in lower case, while the elements of list are in upper case! Start assuming they are not, then modify the code in order to account for this difference.