Exercises 2

Calculate the frequency of each item in a class

Write a function that given a list of items returns a dictionary with the frequency of each kind of item found in the list.

Tip

Alternatively, you could do it using the Counter class and a dict comprenhension.

Solve quadratic equations

A quadratic equation would be: a * x**2 + b * x + c = 0 You can solve it with the quadratic formula.

Write a function that solves the equation and returns its two roots and another function that checks the result. You can even try to solve equations with complex solutions using the cmath module.

Tip

Alternatively you could even solve equations with complex solutions.

Calculate the allelic and genotypic frequencies

For a gene with two alleles an individual could have the genotypes AA, Aa or aa. Calculate the frequencies of these genotypes in the population. Calculate also the allelic frequencies: the number of A and a.

Tip

Read the genetic code into a dictionary

The dictionary should have the codon as the key and the aminoacid name as the value.

Note

splitlines

Tip

Write a program that translates a coding sequence into a protein

Note

You can get the position of every codon using the range function. Remember that range has a step argument that can be set to 3.

Tip

Create a restriction map

Restriction enzymes recognize specific sequences, for instance:

  • EcoRI: GATTC (cuts in the position between G and A, G^ATTC)
  • Hind III : AAGCTT (cuts in the position between A and A, AAGCT^T)

Given a sequence, create the restriction fragments that these two sequences would create:

Tip