Lab Worksheet 8

Problem 1: Create a list with your favor amino acids (use Google if you can't remember your amino acids); your list should have at least 5 amino acids. Then, complete the following steps using Python.

  1. Sort the list so that the amino acids appear in alphabetical order.
  2. Use len() to find the number of items in the list.
  3. Remove any number of amino acids from your list using .remove().
  4. How many amino acids are in your list now? (Use len() again.)
  5. Add the amino acid "selenocysteine" to your list using the function append().
In [1]:
# create a list containing amino acids
# ---your code here---
In [2]:
# sort the list alphabetically
# ---your code here---
In [3]:
# find the length of the list
# ---your code here---
In [4]:
# remove amino acid(s) from the list
# ---your code here---

# find the new length of your list
# ---your code here---
In [5]:
# add selenocysteine to your list
# ---your code here---`

Problem 2: Create a dictionary using the amino acids from the first (unedited) list you created above, where the amino acid is the key and their one-letter code is the value (use Google to find the one-letter codes if you can't remember them). Then, complete the following steps using Python.

  1. Add "selenocysteine" to your dictionary and give it a value of "U".
  2. Remove a key-value pair from your dictionary. Google "python delete entry from dictionary" to find out how.
  3. Print out a list of the keys and a list of the values in your dictionary (i.e., the amino acid names and their one-letter codes).
  4. Create a string from the one-letter codes in your amino acid dictionary. Hint: Use a for loop.
In [6]:
# define a dictionary where the keys are the amino acids
# and the values are the one-letter codes
# ---your code here---
In [7]:
# add a 'selenocysteine' key to the dictionary
# give it a one-letter code (value) of 'U'
# ---your code here---
In [8]:
# remove a key-value pair from the dictionary
# ---your code here---
In [9]:
# define an empty string
# ---your code here---

# loop through the values (letters) in the dictionary
# and add each letter to the string
# ---your code here---


Problem 3: Using only list indexing and the string function split(), write code that extracts the weight (here the number 7) from data_string defined below, and print out the result. What is the type of your final result? Use Python's type() function to find out.

In [10]:
data_string = "height: 15; weight: 7; width: 5;"
# ---your code here---

Problem 4: Using only string indexing, write code that does each of the following. In each case, store the result in a new variable and print its contents.

  1. Extract the first 10 characters from the string data_string.
  2. Extract characters 27 to 52 (corresponding to the upper-case letters of the alphabet) from the string data_string.
  3. Extract characters 1 to 26 (corresponding to the lower-case letters of the alphabet) and characters 53 to 62 (corresponding to the numbers) from the string data_string and combine them into a single, new string that should look like this: "abcdefghijklmnopqrstuvwxyz0123456789"
  4. Replace the letter at position 5 in data_string (the lower-case e) with a captial X. Do not use the function replace().
  5. Take the resulting string from the previous point and convert it all to upper case.
In [11]:
data_string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

# extract the first 10 characters
# ---your code here---

# extract characters 27-52
# ---your code here---

# extract characters 1-26 and 53-62
# ---your code here---

# replace e with X
# ---your code here---

# turn the previous string to uppercase
# ---your code here---