New User Special Price Expires in

Let's log you in.

Sign in with Facebook


Don't have a StudySoup account? Create one here!


Create a StudySoup account

Be part of our community, it's free to join!

Sign up with Facebook


Create your account
By creating an account you agree to StudySoup's terms and conditions and privacy policy

Already have a StudySoup account? Login here

week 3: lists, input and output files, working on sequences/strings

by: Marina Notetaker

week 3: lists, input and output files, working on sequences/strings CSE 6613

Marketplace > Mississippi State University > Buttler Hall > CSE 6613 > week 3 lists input and output files working on sequences strings
Marina Notetaker
GPA 4.0

Preview These Notes for FREE

Get a free preview of these Notes, just enter your email below.

Unlock Preview
Unlock Preview

Preview these materials now for free

Why put in your email? Get access to more of this material and other relevant free materials for your school

View Preview

About this Document

Cover: working on lists, how to make a list, append, pop, basic commands on a list and enough information for next assignment.
Andy Perkins
Class Notes
25 ?




Popular in Bio-computing

Popular in Buttler Hall

This 5 page Class Notes was uploaded by Marina Notetaker on Wednesday August 31, 2016. The Class Notes belongs to CSE 6613 at Mississippi State University taught by Andy Perkins in Fall 2016. Since its upload, it has received 8 views. For similar materials see Bio-computing in Buttler Hall at Mississippi State University.


Reviews for week 3: lists, input and output files, working on sequences/strings


Report this Material


What is Karma?


Karma is the currency of StudySoup.

You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 08/31/16
August 29, 2016 1) Working on lists:  Scales are single values, while lists are multiple values  List is a list of things and it can include numbers and/or letters (strings). List is given by characters separated by a coma inside [ ].  Make a list: list = [ x,z,y]  Lists must have [ ] on either side a. Location of a character on a list: list [location] Note: in this list, number 1 is in the position 0. If you ask for a character in a position that does not exist on the list, it will give an error. b. How many specific character you have repeating on a list: list.count(character) c. To add a character on your list: list.append(character). The new character will always be included at the end of your list. d. To remove a character from your list: list.remove(character). It will always remove the first specific character from your list. e. Give the characters located at specific point: list [start: end]. Don’t forget that the end point is excluded from the list. In this case, on my list a have only once the character 1 and twice the 52, for example. Hello is a string and was inserted in the list by the end of the list. The first 52 on the list was removed, keeping the last one. Just like string operations, you can get the location or find the location from a particular character. So you can get a slice from a list: List [ :x] = gives the list elements from the beginning to x. List [x: ]= giver the list from x to the end of the list. f. Addition between lists, also called concatenate: list2= a + [characters you want to include]. Remember it will include in your first list (a), at the end of that. g. List = 2*other list, means that you do two copies of a list. h. Length of a list: len(list) i. Finding location of strings (index), you do: list.index(‘string name’). So index tell you that your string ‘hello’ is located at 4 place on the list. You can also try to find a string. If the string is not on the list it will tell you, for example ‘hi’. j. Removing the last character from a list: list.pop( ). Or removing a character from a particular location list.pop(location). So, it’s different from list.remove(character), because if you have more than one of this character, you can’t tell which one will be removed. Before removing a character from a list, you can save this character. So for that: save=list.pop ( ) So save will be the name of the last character of the list. You can add again this character by list.append(save). k. Organizing the list in numerical or alphabetical order: list.sort( ). If you have strings with numbers, all elements become alphabetical (includingthe numbers) and in this case you would be a different order. Ex: 1, 17, 5, hello, hi. In this case 17 is read like 1.7. If you have 2 lists, one rely on another because they are supposed to have same characters, so list ‘a = b’. If you do sort in one list, automatically the other one will have same fade. To save the original order from a list: Beforesorting,writethatlist=list1.copy(),then youcansortthelist1andtheoriginal list will keep the same. So it this example, ‘a’ was sorted, while ‘b’ kept the same original order by using b=a.copy( ). l. Deleting characters from specific location: del list [star: end]. Other ways include: list.remove( ) or list.pop( ). 2) Getting the identifier from a list  id(list) = gives you the ID from your list. If you have two lists that as equal ‘a=b’, both lists (‘a’ and ‘b’) will have the same ID. List= [ ] , means that you just opened a list that is empty. Anytime you change your list, it will have a new ID.  To clean a list, you can also use list=[ ]. 3) How to work and open files on your python  Save a file in .txt extension. For example, 5 DNA sequences. a. Open the file: f=open (‘name of file.extension’, ‘r’). Every time you open a file, don’t forget to close it! b. Close a file: f.close( ) c. Print every line from a file use: “for line in f:”, “print (line)”. The problem with this command is that it will print on the keyboard by jumping one line at each written line. d. Taking out the spaces between lines in the keyboard: You have two options! Line = line.strip( ) Print (line, end= ‘ ‘) DON’T USE BOTH TOGETHER! If you use both together it will put together strings from different lines. August 31, 2016 1) Working on a file  Another example of file, that should be saved as “.txt” extension: a. Open a file: f = open (‘file name’, ‘r’), ‘r’ means that you can only read the file, not change it. f= open (‘file name’, ‘w’), ‘w’ means you can write the file and change it. f= open (‘file name’, ‘a’), ‘a’ means b. Asking to enter the file’s name on the keyboard: f= input (‘file name to read:’) c. Calculating mean (average), standard deviation and total length for each sequence.  Standard deviation is the squared root of variance (not written in there!). Must be deviation = stdr(variance). d. Turning your sequences into a list. Each line becomes a sequence Lines = [line.strip() for line in open (‘file name’)] = you turn each line into a strip, so then they will be a list inside a list. And you can print each line separately and analyze each one separately. e. Outputting files As you can see, this codes include:  Opening a file, called inf, just for read (r) a. Give a name to your output. Outfile = ‘name.txt’ b. Opening an output file that will have the name ‘output.txt’, in which you will write (w). Ouf = open (‘file name’, ‘w’) c. To write your output file with each character in a different line you add ‘\n’. d. To insert any information in your output file you must write file name.write( whatever you want)  You can insert as many as output files as you want. This example has 3. Always: - Name your output file: outfile = ‘name.txt’ - Open your file: ouf=open (outfile, ‘w’) - Print whatever you want in the file: ouf.write(…)  This oufwrite commands to write the specific line/ string/ list, : and the length of the line.  ‘\n’ means that if more than one line/ string will be written, it you go to a second line in the output.


Buy Material

Are you sure you want to buy this material for

25 Karma

Buy Material

BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.


You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

Why people love StudySoup

Jim McGreen Ohio University

"Knowing I can count on the Elite Notetaker in my class allows me to focus on what the professor is saying instead of just scribbling notes the whole time and falling behind."

Allison Fischer University of Alabama

"I signed up to be an Elite Notetaker with 2 of my sorority sisters this semester. We just posted our notes weekly and were each making over $600 per month. I LOVE StudySoup!"

Steve Martinelli UC Los Angeles

"There's no way I would have passed my Organic Chemistry class this semester without the notes and study guides I got from StudySoup."

Parker Thompson 500 Startups

"It's a great way for students to improve their educational experience and it seemed like a product that everybody wants, so all the people participating are winning."

Become an Elite Notetaker and start selling your notes online!

Refund Policy


All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email


StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here:

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.