mvoorhie@virgil:~/Projects/Courses/PracticalBioinformatics/python$ cd examples/ mvoorhie@virgil:~/Projects/Courses/PracticalBioinformatics/python/examples$ python Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> d = {"A":"T","T":"A","C":"G","G","C"} File "", line 1 d = {"A":"T","T":"A","C":"G","G","C"} ^ SyntaxError: invalid syntax >>> d = {"A":"T","T":"A","C":"G","G":"C"} >>> d["A"] 'T' >>> d["G"] 'C' >>> d["G"] = "T" >>> d {'A': 'T', 'C': 'G', 'T': 'A', 'G': 'T'} >>> d["G"] = ["T","A"] >>> d["G"] ['T', 'A'] >>> from random import choice >>> s = "".join(choice("ATGC") for i in xrange(20)) >>> s 'AGGACGCGGCTACCGTCACT' >>> p = {} >>> for (i,c) in enumerate(s): ... try: ... p[c].append(i) ... except KeyError: ... p[c] = [i] ... >>> p {'A': [0, 3, 11, 17], 'C': [4, 6, 9, 12, 13, 16, 18], 'T': [10, 15, 19], 'G': [1, 2, 5, 7, 8, 14]} >>> for (key,val) p.items(): File "", line 1 for (key,val) p.items(): ^ SyntaxError: invalid syntax >>> for (key,val) in p.items(): ... print key, len(val) ... A 4 C 7 T 3 G 6 >>> p["T"] [10, 15, 19] >>> >>> d {'A': 'T', 'C': 'G', 'T': 'A', 'G': ['T', 'A']} >>> d["G"] = "C" >>> d {'A': 'T', 'C': 'G', 'T': 'A', 'G': 'C'} >>> s 'AGGACGCGGCTACCGTCACT' >>> for i in reverse("palindrome"): ... print i ... Traceback (most recent call last): File "", line 1, in NameError: name 'reverse' is not defined >>> for i in reversed("palindrome"): ... print i ... e m o r d n i l a p >>> def f(i,j): ... if(i == j): ... File "", line 2 if(i == j): ^ IndentationError: expected an indented block >>> def score(i,j): ... if(i == j): ... return 1.0 ... else: ... return -1.0 ... >>>