Question 1:

For basic operation using list, tuple and dictionaries

1.1

a. Finds the largest of a list of numbers.
Hint: Set up the list as the first line in your program.
Output: The largest number in the list is 26


In [9]:
#type your code here


The largest number in the list is 26

1.1

b. Find the average of a list of numbers using a for loop


In [1]:
runningTotal = 0
listOfNumbers = [4,7,9,1,8,6]

#type your code here

print(listOfNumbers)
print("The average of these numbers is {0:.2f}".format(average))


[4, 7, 9, 1, 8, 6]
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-ae667733b08f> in <module>()
      5 
      6 print(listOfNumbers)
----> 7 print("The average of these numbers is {0:.2f}".format(average))

NameError: name 'average' is not defined

1.1

c. Write a program that prints string in reverse. Print character by character

Input: Python Expected Output: n o h t y P

Hint: can use range, len functions
P y t h o n 0 1 2 3 4 5 -6 -5 -4 -3 -2 -1


In [2]:
word = "Python"
print(len(word))

#type your code here

1.2

Write a Python program to count the number of even and odd numbers from a series of numbers.
Hint: review of for loop, if statements


In [65]:
numbers = (1, 2, 3, 4, 5, 6, 7, 8, 9) # Declaring the tuple
count_odd = 0
count_even = 0

#type your code here

print("Number of even numbers :",count_even)
print("Number of odd numbers :",count_odd)


Number of even numbers : 4
Number of odd numbers : 5

1.3

Check if given list of strings have ECORI site motif and print value that doesn't contain the motif until two strings with the motif are found motif = "GAATTC" (5' for ECORI restriction site)

Output:
AGTGAACCGTCAGATCCGCTAGCGCGAATTC doesn't contain the motif GGAGACCGACACCCTCCTGCTATGGGTGCTGCTGCTC doesn't contain the motif TGGGTGCCCGGCAGCACCGGCGACGCACCGGTCGC doesn't contain the motif CACCATGGTGAGCAAGGGCGAGGAGAATAACATGGCC doesn't contain the motif Two strings in given list contain the motif


In [66]:
motif = "GAATTC"
count = 0
dna_strings = ['AGTGAACCGTCAGATCCGCTAGCGCGAATTC','GGAGACCGACACCCTCCTGCTATGGGTGCTGCTGCTC','TGGGTGCCCGGCAGCACCGGCGACGCACCGGTCGC',
               'CACCATGGTGAGCAAGGGCGAGGAGAATAACATGGCC','ATCATCAAGGAGTTCATGCGCTTCAAGAATTC','CATGGAGGGCTCCGTGAACGGCCACGAGTTCGAGA'
               ,'TCGAGGGCGAGGGCGAGGGCCGCCCCTACGAGGCCTT']
#type your code


AGTGAACCGTCAGATCCGCTAGCGCGAATTC : doesn't contain the motif
GGAGACCGACACCCTCCTGCTATGGGTGCTGCTGCTC : doesn't contain the motif
TGGGTGCCCGGCAGCACCGGCGACGCACCGGTCGC : doesn't contain the motif
CACCATGGTGAGCAAGGGCGAGGAGAATAACATGGCC : doesn't contain the motif
Two strings in given list contain the motif

1.4

Write a Python program that prints all the numbers in range from 0 to 10 except 5 and 10.
Hint: use continue


In [67]:
#type your code here


0 1 2 3 4 6 7 8 9 

1.5 (Multi-Part)

Next series of tasks about lists and list manipulations:
a. Create a list of 5 of your favorite things.


In [68]:
#type your code

b. Use the print() function to print your list.


In [69]:
#type your code


['Music', 'Movies', 'Coding', 'Biology', 'Python']

c. Use the print() function to print out the middle element.


In [70]:
#type your code


Coding

d. Now replace the middle element with a different item, your favorite song, or song bird.


In [71]:
#type your code

e. Use the same print statement from b. to print your new list. Check out the differences.


In [72]:
#type your code


['Music', 'Movies', 'European robin', 'Biology', 'Python']

f. Add a new element to the end. Read about append().


In [74]:
#type your code

g. Add a new element to the beginning. Read about insert().


In [75]:
#type your code

h. Add a new element somewhere other than the beginning or the end.


In [76]:
#type your code

1.6

Write a script that splits a string into a list:

  • Save the string sapiens, erectus, neanderthalensis as a variable.
  • Print the string.
  • Split the string into individual words and print the result of the split. (Think about the ', '.)
  • Store the resulting list in a new variable.
  • Print the list.
  • Sort the list alphabetically and print (hint: lookup the function sorted()).
  • Sort the list by length of each string and print. (The shortest string should be first). Check out documentation of the key argument.`

In [77]:
#type your code


sapiens, erectus, neanderthalensis
hominin_individuals
List:  [' erectus', ' neanderthalensis', 'sapiens']
['sapiens', ' erectus', ' neanderthalensis']

Question 2: Dictionaries and Set

2.1

Create a dictionary store DNA restriction enzyme names and their motifs from:
https://www.neb.com/tools-and-resources/selection-charts/alphabetized-list-of-recognition-specificities
eg: EcoRI = GAATTC AvaII = GGACC BisI = GGACC


In [79]:
#type your code


{'EcoRI': 'GAATTC', 'AvaII': 'GGACC', 'BisI': 'GCATGCGC', 'SacII': 'CCGCGG', 'BamHI': 'GGATCC'}

a. look up the motif for a particular SacII enzyme


In [80]:
#type your code


CCGCGG

b. add below two enzymes and their motifs to dictionary
KasI: GGCGCC AscI: GGCGCGCC EciI: GGCGGA


In [81]:
#type your code


{'EcoRI': 'GAATTC', 'AvaII': 'GGACC', 'BisI': 'GCATGCGC', 'SacII': 'CCGCGG', 'BamHI': 'GGATCC', 'KasI': 'GGCGCC', 'AscI': 'GGCGCGCC'}

2.2

Suppose dna is a string variable that contains only 'A','C','G' or 'T' characters. Write code to find and print the character and frequency (max_freq) of the most frequent character in string dna?
Output: {'T': 5, 'C': 2, 'G': 3, 'A': 6}
6


In [3]:
dna = 'AAATTCGTGACTGTAA'
#type your code here


{'T': 5, 'C': 2, 'G': 3, 'A': 6}
6

2.3

If you create a set using a DNA sequence, what will you get back? Try it with this sequence:

GATGGGATTGGGGTTTTCCCCTCCCATGTGCTCAAGACTGGCGCTAAAAGTTTTGAGCTTCTCAAAAGTCTAGAGCCACCGTCCAGGGAGCAGGTAGCTGCTGGGCTCCGGGGACACTTTGCGTTCGGGCTGGGAGCGTGCTTTCCACGACGGTGACACGCTTCCCTGGATTGGCAGCCAGACTGCCTTCCGGGTCACTGCCATGGAGGAGCCGCAGTCAGATCCTAGCGTCGAGCCCCCTCTGAGTCAGGAAACATTTTCAGACCTATGGAAACTACTTCCTGAAAACAACGTTCTGTCCCCCTTGCCGTCCCAAGCAATGGATGATTTGATGCTGTCCCCGGACGATATTGAACAATGGTTCACTGAAGACCCAGGTCCAGATGAAGCTCCCAGAATTCGCCAGAGGCTGCTCCCCCCGTGGCCCCTGCACCAGCAGCTCCTACACCGGCGGCCCCTGCACCAGCCCCCTCCTGGCCCCTGTCATCTTCTGTCCCTTCCCAGAAAACCTACCAGGGCAGCTACGGTTTCCGTCTGGGCTTCTTGCATTCTGGGACAGCCAAGTCTGTGACTTGCACGTACTCCCCTGCCCTCAACAAGATGTTTTGCCAACTGGCCAAGACCTGCCCTGTGCAGCTGTGGGTTGATTCCACACCCCCGCCCGGCACCCGCGTCCGCGCCATGGCCATCTACAAGCAGTCACAGCACATGACGGAGGTTGTGAGGCGCTGCCCCCACCATGAGCGCTGCTCAGATAGCGATGGTCTGGCCCCTCCTCAGCATCTTATCCGAGTGGAAGGAAATTTGCGTGTGGAGTATTTGGATGACAGAAACACTTTTCGTGGGGTTTTCCCCTCCCATGTGCTCAAGACTGGCGCTAAAAGTTTTGAGCTTCTCAAAAGTCTAGAGCCACCGTCCAGGGAGCAGGTAGCTGCTGGGCTCCGGGGACACTTTGCGTTCGGGCTGGGAGCGTGCTTTCCACGACGGTGACACGCTTCCCTGGATTGGCAGCCAGACTGCCTTCCGGGTCACTGCCATGGAGGAGCCGCAGTCAGATCCTAGCGTCGAGCCCCCTCTGAGTCAGGAAACATTTTCAGACCTATGGAAACTACTTCCTGAAAACAACGTTCTGTCCCCCTTGCCGTCCCAAGCAATGGATGATTTGATGCTGTCCCCGGACGATATTGAACAATGGTTCACTGAAGACCCAGGTCCAGATGAAGCTCCCAGAATTCGCCAGAGGCTGCTCCCCCCGTGGCCCCTGCACCAGCAGCTCCTACACCGGCGGCCCCTGCACCAGCCCCCTCCTGGCCCCTGTCATCTTCTGTCCCTTCCCAGAAAACCTACCAGGGCAGCTACGGTTTCCGTCTGGGCTTCTTGCATTCTGGGACAGCCAAGTCTGTGACTTGCACGTACTCCCCTGCCCTCAACAAGATGTTTTGCCAACTGGCCAAGACCTGCCCTGTGCAGCTGTGGGTTGATTCCACACCCCCGCCCGGCACCCGCGTCCGCGCCATGGCCATCTACAAGCAGTCACAGCACATGACGGAGGTTGTGAGGCGCTGCCCCCACCATGAGCGCTGCTCAGATAGCGATGGTCTGGCCCCTCCTCAGCATCTTATCCGAGTGGAAGGAAATTTGCGTGTGGAGTATTTGGATGAC


In [83]:
#type your code here


DNA_set contains {'T', 'G', 'A', 'C'}

Extra Pratice: 1.7

Use list comprehension to generate a list of tuples. The tuples should contain sequences and lengths from the previous problem. Print out the length and the sequence (i.e., "4\tATGC\n").


In [78]:
sequences=['ATGCCCGGCCCGGC','GCGTGCTAGCAATACGATAAACCGG', 'ATATATATCGAT','ATGGGCCC']
#type your code here


[('ATGCCCGGCCCGGC', 14), ('GCGTGCTAGCAATACGATAAACCGG', 25), ('ATATATATCGAT', 12), ('ATGGGCCC', 8)]