# Python List Comprehensions Creating 2-D Lists Overview

The Above Picture is Related Image of Another Journal

## Python List Comprehensions Creating 2-D Lists Overview

Elmira College, US has reference to this Academic Journal, An Introduction so that Python ? Part III Dr. Nancy Warter-Perez Overview Assignments Solution so that Programming Workshop #2 2-D Lists List comprehensions Zip File I/O Split Functions Programming Workshop #3 Solution so that Programming Workshop 2 # Script so that calculate %GC of a sequence of nucleotides. # Inputs: sequence, window size # Outputs: nucleotide number, %GC in consideration of each window # Written by: Nancy Warter-Perez # Date created: April 22, 2004 # Last modified: print(“Script in consideration of computing %GC.”) seq = raw_input(“Please enter sequence: “) winsize = input(“Please enter window size: “)

Related University That Contributed for this Journal are Acknowledged in the above Image

Solution so that Programming Workshop 2 print(“nucleotidet%GC”) in consideration of i in range(0, len(seq)-winsize+1): cnt=0 in consideration of j in seq[i:i+winsize]: if(j==’G’ or j==’C’ or j==’g’ or j == ‘c’): cnt+=1 gc = (cnt*100.0)/winsize print”%itt%.2f”% ((i+1+winsize/2),gc) x = raw_input(“nnPlease enter any character so that exit.n”) Creating 2-D Lists To create a 2-D list L, alongside C columns in addition to R rows initialized so that 0: L = [[]] #empty 2-Dlist L = [[0 in consideration of col in range(C)] in consideration of row in range(R)] To assign the value 5 so that the element at the 2nd row in addition to 3rd column of L L[2][3] = 5 Python List Comprehensions Precise way so that create a list Consists of an expression followed by a in consideration of clause, then zero or more in consideration of or if clauses Ex: >>> [str(round(355/113.0, i)) in consideration of i in range(1,6)] [‘3.1’, ‘3.14’, ‘3.142’, ‘3.1416’, ‘3.14159’] Ex: replace all occurrences or G or C in a string of amino acids alongside a 1 in addition to A in addition to T alongside a 0 >>> x = “acactgacct” >>> y = [int(i==’c’ or i==’g’) in consideration of i in x] >>> y [0, 1, 0, 1, 0, 1, 0, 1, 1, 0]

Zip ? in consideration of parallel traversals Visit multiple sequences in parallel Ex: >>> L1 = [1,2,3] >>> L2 = [5,6,7] >>> zip(L1, L2) [(1,5), (2,6), (3,7)] Ex: >>> for(x,y) in zip(L1, L2): ? print x, y, ‘ ‘, x+y 1 5 6 2 6 8 3 7 10 More on Zip Zip more than two arguments in addition to any type of sequence Ex: >>> T1, T2, T3 = (1,2,3),(4,5,6),(7,8) >>> T3 (7,8) >>> zip(T1, T2, T3) [(1,4,7),(2,5,8)] truncates so that shortest sequence Dictionary Construction alongside zip Ex: >>> keys = [‘a’, ‘b’, ‘d’] >>> vals = [1.8, 2.5, -3.5] >>> hydro = dict(zip(keys,vals)) >>> hydro {‘a’: 1.8, ‘b’: 2.5, ‘d’: -3.5}

2-part models RAND HIE

File I/O To open a file myfile = open(‘pathname’, ) modes: ‘r’ = read ‘w’ = write Ex: infile = open(“D:\Docs\test.txt”, ‘r’) Ex: outfile = open(“out.txt”, ‘w’) ? in same directory Common input file operations Common output file operations

Extracting data from string ? split String.split([sep, [maxsplit]]) – Return a list of the words of the string s. If the optional second argument sep is absent or None, the words are separated by arbitrary strings of whitespace characters (space, tab, newline, return, formfeed). If the second argument sep is present in addition to not None, it specifies a string so that be used as the word separator. The optional third argument maxsplit defaults so that 0. If it is nonzero, at most maxsplit number of splits occur, in addition to the remainder of the string is returned as the final element of the list (thus, the list will have at most maxsplit+1 elements). Split Ex: >>> x = “a,b,c,d” >>> x.split(‘,’)[‘a’, ‘b’, ‘c’, ‘d’] >>> x.split(‘,’,2)[‘a’, ‘b’, ‘c,d’] Ex: >>> y = “5 33 a 4” >>> y.split()[‘5′, ’33’, ‘a’, ‘4’] Functions Function definition def adder(a, b, c): return a+b+c Function calls adder(1, 2, 3) -> 6

Functions ? Polymorphism >>>def fn2(c): ? a = c * 3 ? return a >>> print fn2(5) 15 >>> print fn2(1.5) 4.5 >>> print fn2([1,2,3]) [1,2,3,1,2,3,1,2,3] >>> print fn2(“Hi”) HiHiHi Functions – Recursion def fn_Rec(x): if x == []: return fn_Rec(x[1:]) print x[0], y = [1,2,3,4] fn_Rec(y) >>> 4 3 2 1 Using Tuples so that Pass Variables >>>M = max((63, “Curly”),(77, “Larry”), (95, “Moe”)) >>>print M (95, “Moe”) >>>print M[0] 95 >>>print M[1] Moe

Programming Workshop #3 Write a program so that prompt the user in consideration of a scoring matrix file name in addition to read the data into a dictionary ftp://ftp.ncbi.nih.gov/blast/matrices/

## Greenlaw, Bruce Morning and Afternoon On-Air Personality

Greenlaw, Bruce is from United States and they belong to Morning and Afternoon On-Air Personality and work for KESZ-FM in the AZ state United States got related to this Particular Article.

## Journal Ratings by Elmira College

This Particular Journal got reviewed and rated by and short form of this particular Institution is US and gave this Journal an Excellent Rating.