List Comprehensions, Data Analysis & Sorting
|
|
- Annabel Ramsey
- 5 years ago
- Views:
Transcription
1 List Comprehensions, Data Analysis & Sorting From last time: remember our functions using list comprehensions? def linesfromfile(filename): '''Returns a list of all lines in the given file. In each line, the terminating newline has been removed.''' with open(filename, 'r') as inputfile: # open the file thelines = [line.strip() for line in inputfile] return thelines CS111 Computer Programming Department of Computer Science Wellesley College def tuplesfromcsvfile(fname): '''Returns a list of tuples, one for each line in fname. ' tuplessofar = [tuple(line.split(', ) for line in linesfromfile(fname)] return tuplessofar 12-2 linesfromfile + tuplesfromcsvfile = tuplesfromfile def linesfromfile(filename): '''Returns a list of all lines in the given file. In each line, the terminating newline has been removed.''' with open(filename, 'r') as inputfile: # open the file thelines = [line.strip() for line in inputfile] return thelines + From last time: allstudents = tuplesfromfile('cs111spring16.csv') [ def tuplesfromcsvfile(fname): '''Returns a list of tuples, one for each line in fname. ' tuplessofar = [tuple(line.split(', ) for line in linesfromfile(fname)] return tuplessofar = def tuplesfromfile(filename): '' Merge linesfromfile and tuplesfromcsvfile into one''' with open(filename, 'r') as inputfile: thetuples = [tuple(line.strip().split(',')) for line in inputfile] return thetuples 12-3 ] In [33]: len(allstudents) Out[33]: 70 In [35]: allstudents[47] Out[35]:('Lia Wang', 'lwang3', '2016', 'Stone Hall', '3 ) In [36]: allstudents[47][0] Out[36]: 'Lia Wang' 12-4
2 for loop mapping pattern vs. list comprehension for loop mapping pattern names = [] names.append(stu[0]) # names contains all names equivalent list comprehension # A list of all names List Comprehensions: Mapping Examples Explain in English before trying them in the notebook. fs = [] fs.append(s[0].split()[0]) # fs contains all first names # A list of all first names [s[3] for s in allstudents] [s[0].split()[-1] for s in allstudents] [s[0].split()[-1] + ' ' + s[2] for s in allstudents] ans = [] for var in somelist: ans.append(expusingvar) # ans is list of results # A list of all results [expusingvar for var in somelist] for loop filtering pattern seniors = [] if s[2] == '2016': seniors.append(s) # seniors has all seniors tows = [] if s[3].startswith('tow'): tows.append(s) # tows has all entries for # students living in Tower ans = [] for var in somelist: if predicateusingvar: ans.append(var) # ans is all elements for # which predicate is true equivalent list comprehension # List of all senior entries # A list of all entries for # students in Tower # A list of all elements for # which predicate is true [var for var in somelist if predicateusingvar] List Comprehensions: Filtering Examples Explain them in English before trying them in the notebook. len([s for s in allstudents if s[2] == '2019']) [s for s in allstudents if s[2] == '2019' and s[3].startswith('tow')] [s for s in allstudents if s[0].split()[0][-1] == 'y']
3 Improving readability with abstractions Define some helpful abstractions: def getcolumn(index, table): return [row[index] for row in table] def firstname(name): return name.split()[0] def lastname(name): return name.split()[-1] What lists are described by these expressions? getcolumn(3, allstudents) List comprehensions with both mapping and filtering Explain in English before trying them in the notebook [s[0] for s in allstudents if s[4] == '2' and s[3].startswith('s')] [firstname(s[0]) for s in allstudents if s[2] == '2016'] [lastname(name) for name in getcolumn(0, allstudents) if firstname(name).endswith('y')] [firstname(name) for name in getcolumn(0, allstudents)] [lastname(name) for name in getcolumn(0, allstudents)] More examples len([name for name in getcolumn(0, allstudents) if firstname(name)[-1] in 'aeiou']) Pie Chart [first for first in [firstname(name) for name in getcolumn(0, allstudents)] if first.endswith('n')] plt.figure(8, figsize=(4,4), facecolor='white') classes = [6,10,19,35] # seniors, juniors, sophs, first-years plt.title('cs111 Class distribution') classcolors = ['red', 'green', 'purple','yellow'] years = ['2016', '2017', '2018','2019'] # pie makes the pie chart plt.pie(classes, labels = years, colors =classcolors) plt.show() # make the plot visible
4 Python built-in functions: sorted( ) and.sort( ) ages = [5,2,8,4,2,0] ages_in_order = sorted(ages) ages_rev_order = sorted(ages, reverse=true) Now let s look at our variables: ages_in_order ages_rev_order ages ages [0,2,2,4,5,8] [8,5,4,2,2,0] [5,2,8,4,2,0] # unchanged # changes the content of ages Another look at our variables: ages [0,2,2,4,5,8] Sorting with tuples # students who live in Caz firstyearscaz = [s for s in allstudents if s[2]=='2019' and s[3].startswith('caz')] [('Chloe Blazey', 'cblazey', '2019', 'Cazenove Hall', '2'), ('Dana Fein-Schaffer', 'dfeinsch', '2019', 'Cazenove Hall', '3'), ('Barakah Quader', 'bquader', '2019', 'Cazenove Hall', '3'), ('Halle Rubera', 'crubera', '2019', 'Cazenove Hall', '3'), ('Noor Pirani', 'npirani', '2019', 'Cazenove Hall', '1'), ('Claire Whitaker', 'cwhitak4', '2019', 'Cazenove Hall', '1'), ('Vivian Zhang', 'vzhang3', '2019', 'Cazenove Hall', '1'), ('Yiting Zhang', 'yzhang16', '2019', 'Cazenove Hall', '1')] sorted(firstyearscaz) [('Barakah Quader', 'bquader', '2019', 'Cazenove Hall', '3'), ('Chloe Blazey', 'cblazey', '2019', 'Cazenove Hall', '2'), ('Claire Whitaker', 'cwhitak4', '2019', 'Cazenove Hall', '1'), ('Dana Fein-Schaffer', 'dfeinsch', '2019', 'Cazenove Hall', '3'), ('Halle Rubera', 'crubera', '2019', 'Cazenove Hall', '3'), ('Noor Pirani', 'npirani', '2019', 'Cazenove Hall', '1'), ('Vivian Zhang', 'vzhang3', '2019', 'Cazenove Hall', '1'), ('Yiting Zhang', 'yzhang16', '2019', 'Cazenove Hall', '1')] sorted([lastname(s[0])for s in firstyearscaz]) ['Blazey', 'Fein-Schaffer', 'Pirani', 'Quader', 'Rubera', 'Whitaker', 'Zhang', 'Zhang'] Sorting with tuples farm = [('lassie',8), ('wilbur', 2),('charlotte',1), ('garfield',10),('pooh', 20),('eeyore',15)] sorted(farm) # sort first by 0 th slot, then 1 st, etc. [('charlotte', 1), ('eeyore', 15), ('garfield', 10), ('lassie', 8), ('pooh', 20), ('wilbur', 2)] sorted([animal[0] for animal in farm]) ['charlotte', 'eeyore', 'garfield', 'lassie', 'pooh', 'wilbur'] Sorting with tuples by a given slot [aka decorate-sort-undecorate] animal_age_tuplist = [(animal[1], animal) for animal in farm] sorted(animal_age_tuplist) [(1, ('charlotte', 1)), (2, ('wilbur', 2)), (8, ('lassie', 8)), (10, ('garfield', 10)), (15, ('eeyore', 15)), (20, ('pooh', 20))] getcolumn(1, sorted(animal_age_tuplist)) [(8, ('lassie', 8)), (2, ('wilbur', 2)), (1, ('charlotte', 1)), (10, ('garfield', 10)), (20, ('pooh', 20)), (15, ('eeyore', 15))] sorted([animal[1] for animal in farm]) [1, 2, 8, 10, 15, 20] [('charlotte', 1), ('wilbur', 2), ('lassie', 8), ('garfield', 10), ('eeyore', 15), ('pooh', 20)] 12-16
5 Another decorate/sort/undecorate example: firsts = ['Ann', Bea', Cat', Dee'] lasts = ['Park', 'Smith', 'Lu'] first_last_tups = zip(firsts,lasts) [('Ann', 'Park'), ('Bea', 'Smith'), ('Cat', 'Lu')] Make new tuple with last name, first_last tuple [('Park', ('Ann', 'Park')), ('Smith', ('Bea', 'Smith')), ('Lu', ('Cat', 'Lu'))] Sort decorated tuples by last name [('Lu', ('Cat', 'Lu')), ('Park', ('Ann', 'Park')), ('Smith', ('Bea', 'Smith'))] Extract the first_last tuple, now sorted by last name [('Cat', 'Lu'), ('Ann', 'Park'), ('Bea', 'Smith')] Sets are collections of items with no duplicates In [155]: dormlist = getcolumn(3, allstudents) In [156]: len(dormlist) Out[156]: 70 In [157]: dormset = # how can you get the unique dorms? In [158]: dormset Out[158]: {'Bates Hall, 'Beebe Hall, 'Cazenove Hall, 'Claflin Hall, 'Davis Hall, 'Dower House, 'Freeman Hall, 'Lake House, 'McAfee Hall, 'Munger Hall, 'Pomeroy Hall, 'Severance Hall', 'Shafer Hall, 'Stone Hall, 'Tower Court East, 'Tower Court West'} In [159]: len(dormset) Out[159]: Sets are collections of items with no duplicates Let s create some new tuples with the number of students in each dorm with the name of the dorm In [160]: studentcountperdorm = # write in notebook In [161]: studentcountperdorm Out[161]: [(2, 'Dower House'), (3, 'Tower Court East'), (3, 'Stone Hall'), (1, 'Lake House'), (6, 'Munger Hall'), (13, 'Cazenove Hall'), (6, 'Freeman Hall'), (6, 'Severance Hall'), (6, 'Shafer Hall'), (9, 'McAfee Hall'), (11, 'Beebe Hall'), (9, 'Tower Court West'), (3, 'Bates Hall'), (4, 'Claflin Hall'), (4, 'Davis Hall'), (6, 'Pomeroy Hall')] Sorting exercises sorted(allstudents) sorted(studentcountperdorm, reverse=true) getcolumn(1, sorted([(lastname(s[0]), s) for s in allstudents])) getcolumn(2, sorted([(s[2], lastname(s[0]), s) for s in allstudents])
6 Make a list of dictionaries, one for each student # create a list of dictionaries, one dict per student # to store the data for each student studentdctinlist = [] for stu in allstudents: stdct = {'name': stu[0], 'section': stu[1], 'year': stu[2], 'dorm': stu[3]} studentdctinlist.append(stdct) print studentdctinlist[14] Now, with this list of dictionaries, we can write more readable code: We can: Find all juniors Find all sophomores in your section And lots of other things Organize our students by year Scenario 1: We know the keys studentsbyyeardct = {'2016': [], '2017': [], '2018': [], '2019': []} Scenario 2: We do not know the keys studentsbyyeardct2 = {} # we start with an empty dict Dictionary Comprehension Very much like list comprehensions: {mykey: myvalue for item in mylist} Example: {x: x**2 for x in (2, 4, 6)} produces {2: 4, 4: 16, 6: 36} Let s write a dictionary comprehension to produce a list of names and length of the names: Hikari Murayama 14 Mina Oh 6 Yu Chi 5 Caroline Martin 14 Stacey Kim 9 Meher Vohra 10 Midori Yang 10 Shaina Ma 8 Anne Shen Dictionary Comprehension len( Anne Shen ) 9 We need to replace the space with an empty string: Anne Shen.replace(, ) AnneShen len( AnneShen ) 8 totallettersinnames = {KEY: VALUE for studct in studentdctinlist} Write the python expressions for KEY and VALUE in the notebook to generate the dictionary comprehension 12-24
File Operations. Working with files in Python. Files are persistent data storage. File Extensions. CS111 Computer Programming
File Operations Files are persistent data storage titanicdata.txt in PS06 Persistent vs. volatile memory. The bit as the unit of information. Persistent = data that is not dependent on a program (exists
More informationFile Operations. Working with files in Python. Files are persistent data storage. File Extensions. CS111 Computer Programming
File Operations Files are persistent data storage titanicdata.txt in PS07 Persistent vs. volatile memory. The bit as the unit of information. Persistent = data that is not dependent on a running program
More informationDictionaries. Looking up English words in the dictionary. Python sequences and collections. Properties of sequences and collections
Looking up English words in the dictionary Comparing sequences to collections. Sequence : a group of things that come one after the other Collection : a group of (interesting) things brought together for
More informationCompSci 101 Exam 2 Sec01 Fall 2017
CompSci 101 Exam 2 Sec01 Fall 2017 PROBLEM 1 : (What is the output? (18 points)) Part A. What is the output of the following code segments? Write the output to the right. Note that there is only output
More informationMultivariate Data More Overview
Multivariate Data More Overview CS 4460 - Information Visualization Jim Foley Last Revision August 2016 Some Key Concepts Quick Review Data Types Data Marks Basic Data Types N-Nominal (categorical) Equal
More information(b) If a heap has n elements, what s the height of the tree?
CISC 5835 Algorithms for Big Data Fall, 2018 Homework Assignment #4 1 Answer the following questions about binary tree and heap: (a) For a complete binary tree of height 4 (we consider a tree with just
More informationLecture 7: Lambda & Abstract Data Types
UC Berkeley EECS Adj. Ass. Prof. Dr. Gerald Friedland Computational Structures in Data Science Lecture 7: Lambda & Abstract Data Types Computational Concepts Toolbox Data type: values, literals, operations,
More informationBooleans, Logical Expressions, and Predicates
Making Decisions Real-life examples for decision making with Boolean values., Logical Expressions, and Predicates If it s raining then bring umbrella and wear boots. CS111 Computer Programming Department
More informationCSE 115. Introduction to Computer Science I
CSE 115 Introduction to Computer Science I Road map Review (sorting) Empirical Demo Defining Custom Sorts Sorting Given a sequence of values that can be ordered, sorting involves rearranging these values
More informationFunctions, Scope & Arguments. HORT Lecture 12 Instructor: Kranthi Varala
Functions, Scope & Arguments HORT 59000 Lecture 12 Instructor: Kranthi Varala Functions Functions are logical groupings of statements to achieve a task. For example, a function to calculate the average
More informationFunctional Programming
Functional Programming 1 / 13 Functional Features in Python Functions are first class, meaning they can be stored in variables and data structures passed as arguments to functions returned from functions
More informationLECTURE 3 Python Basics Part 2
LECTURE 3 Python Basics Part 2 FUNCTIONAL PROGRAMMING TOOLS Last time, we covered function concepts in depth. We also mentioned that Python allows for the use of a special kind of function, a lambda function.
More informationSECURITY AND CAMPUS SAFETY
SECURITY AND CAMPUS SAFETY Clery Act Public Crime Log From 10/1/201 To 10/31/201 CAMPUS BUILDINGS : Pettengill Hall - 4 Andrews Road Date/Time Reported: 10/1/201 0006 Incident Occurred Between: 10/1/201
More informationCollections. Lists, Tuples, Sets, Dictionaries
Collections Lists, Tuples, Sets, Dictionaries Homework notes Homework 1 grades on canvas People mostly lost points for not reading the document carefully Didn t play again Didn t use Y/N for playing again
More informationLab 6: Data Types, Mutability, Sorting. Ling 1330/2330: Computational Linguistics Na-Rae Han
Lab 6: Data Types, Mutability, Sorting Ling 1330/2330: Computational Linguistics Na-Rae Han Objectives Data types and conversion Tuple Mutability Sorting: additional parameters Text processing overview
More informationData Visualization (DSC 530/CIS )
Data Visualization (DSC 530/CIS 602-02) Web Programming Dr. David Koop 2 What languages do we use on the Web? 3 Languages of the Web HTML CSS SVG JavaScript - Versions of Javascript: ES6, ES2015, ES2017
More informationPython for Finance. Advanced Features. Andras Niedermayer
Python for Finance Advanced Features Andras Niedermayer Objects of Interest object oriented programming (Wikipedia) Definition (Object-oriented Programming) Object-oriented programming (OOP) is a programming
More informationCSE 115. Introduction to Computer Science I
CSE 115 Introduction to Computer Science I Road map Review (sorting) Persisting data Databases Sorting Given a sequence of values that can be ordered, sorting involves rearranging these values so they
More informationPython Review IPRE
Python Review Jay Summet 2005-12-31 IPRE Outline Compound Data Types: Strings, Tuples, Lists & Dictionaries Immutable types: Strings Tuples Accessing Elements Cloning Slices Mutable Types: Lists Dictionaries
More informationTopic 7: Lists, Dictionaries and Strings
Topic 7: Lists, Dictionaries and Strings The human animal differs from the lesser primates in his passion for lists of Ten Best H. Allen Smith 1 Textbook Strongly Recommended Exercises The Python Workbook:
More informationCS101 - Text Processing Lecture 8
CS101 - Text Processing Lecture 8 School of Computing KAIST 1 / 16 Roadmap Last week we learned Data structures String Set Dictionary Image processing 2 / 16 Roadmap Last week we learned Data structures
More informationDecorate, sort, undecorate pattern
Decorate, sort, undecorate pattern In a previous example, we read a file that contained data about Words with Friends games between me and my sister. Suppose we want to read this data again, and this time
More informationReading and Writing Files
Reading and Writing Files 1. def find_dups(l): (list) -> set 2. Return the number of duplicates numbers from L. >>> find_dups([1, 1, 2, 3, 4, 2]) {1, 2} >>> find_dups([1, 2, 3, 4]) set() elem_set = set()
More informationPython Lists, Tuples, Dictionaries, and Loops
Python Lists, Tuples, Dictionaries, and Loops What you need to Know For this lecture you need to know: 1. How to write and run basic python programs 2. How to create and assign data to variables 3. How
More informationFunctions. Genome 559: Introduction to Statistical and Computational Genomics Elhanan Borenstein
Functions Genome 559: Introduction to Statistical and Computational Genomics Elhanan Borenstein Dictionaries: key:value pairs A quick review a.k.a. hash tables, lookup tables Examples: Word and definition
More informationMore Loop Examples Functions and Parameters
More Loop Eamples Functions and Parameters Eample: min difference Given two of numbers, compute the minimum difference among any pair of numbers, one from each. E.g., 1 = [1, 2, 3, 4], 2 = [-2, 10, 5,
More informationList Processing Patterns and List Comprehension
List Processing Patterns and Review: Lists Summary of what we know about lists. A list is a sequence type (like strings and tuples), but that differently from them is mutable (it can change). Lists can
More informationLists. Lists Element Types. Creating Lists. CS 112 Lists Part II 2/22/09. Dan Fleck Spring 2009 George Mason University
Lists CS 112 Lists Part II Dan Fleck Spring 2009 George Mason University One of the sequence data types (tuples, strings, lists) Sequence: indexed from 0 to len(thelist) 1 Mutable: Able to change internal
More informationDatabase Languages. A DBMS provides two types of languages: Language for accessing & manipulating the data. Language for defining a database schema
SQL 1 Database Languages A DBMS provides two types of languages: DDL Data Definition Language Language for defining a database schema DML Data Manipulation Language Language for accessing & manipulating
More informationENGR/CS 101 CS Session Lecture 12
ENGR/CS 101 CS Session Lecture 12 Log into Windows/ACENET (reboot if in Linux) Use web browser to go to session webpage http://csserver.evansville.edu/~hwang/f14-courses/cs101.html Right-click on lecture12.py
More informationLists, Tuples and Dictionaries. HORT Lecture 10 Instructor: Kranthi Varala
Lists, Tuples and Dictionaries HORT 59000 Lecture 10 Instructor: Kranthi Varala Core data types Numbers Strings Lists Dictionaries Tuples Files Sets References and dynamic typing Dynamic typing allows
More informationIntroduction to programming Lecture 5
Introduction to programming Lecture 5 UNIVERSITY OF Richard Johansson September 29, 2015 the exam location: Viktoriagatan 30 time: October 19, 9:0012:00, make sure to be on time! bring a valid ID document
More informationPYTHON DATA SCIENCE TOOLBOX II. List comprehensions
PYTHON DATA SCIENCE TOOLBOX II List comprehensions Populate a list with a for loop In [1]: nums = [12, 8, 21, 3, 16] In [2]: new_nums = [] In [3]: for num in nums:...: new_nums.append(num + 1) In [4]:
More informationDictionaries. Upsorn Praphamontripong. CS 1111 Introduction to Programming Spring 2018
Dictionaries Upsorn Praphamontripong CS 1111 Introduction to Programming Spring 2018 How do Computer Programs Fit in with the World Around Them? Thing (object type): Hotel Thing (object type): Car Thing
More informationAnnouncements. Lecture Agenda. Class Exercise. Hashable. Mutability. COMP10001 Foundations of Computing Iteration
COMP10001 Foundations of Computing Iteration Announcements Semester 1, 2017 Tim Baldwin & Egemen Tanin First Guest Lecture on Friday (examinable) Grok Worksheets 5 7 due at the end of this week version:
More informationPython. Olmo S. Zavala R. Python Data Structures. Lists Tuples Dictionaries. Center of Atmospheric Sciences, UNAM. August 24, 2016
Center of Atmospheric Sciences, UNAM August 24, 2016 are the most versatile datatype available in. It can be seen as a container of other types of variables. are identified with square brackets and its
More informationCS434 Notebook. April 19. Data Mining and Data Warehouse
CS434 Notebook April 19 2017 Data Mining and Data Warehouse Table of Contents The DM Process MS s view (DMX)... 3 The Basics... 3 The Three-Step Dance... 3 Few Important Concepts... 4 More on Attributes...
More informationAbstract Data Types. David E. Culler CS8 Computational Structures in Data Science Lecture 7 March 7, 2016
Abstract Data Types David E. Culler CS8 Computational Structures in Data Science http://inst.eecs.berkeley.edu/~cs88 Lecture 7 March 7, 2016 Computational Concepts Toolbox Data type: values, literals,
More informationCIS192: Python Programming
CIS192: Python Programming Introduction Harry Smith University of Pennsylvania January 18, 2017 Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 1 / 34 Outline 1 Logistics Rooms
More informationData Abstraction. UW CSE 160 Spring 2015
Data Abstraction UW CSE 160 Spring 2015 1 What is a program? What is a program? A sequence of instructions to achieve some particular purpose What is a library? A collection of functions that are helpful
More informationSkittles Excel Project
Skittles Excel Project Entering Your Data and Creating Data Displays 1. Open Microsoft Excel 2. Create a table for your Skittles colors: a. In cell A1 type in a title for your chart b. In cell A2 type
More informationAbstract Data Types. CS 234, Fall Types, Data Types Abstraction Abstract Data Types Preconditions, Postconditions ADT Examples
Abstract Data Types CS 234, Fall 2017 Types, Data Types Abstraction Abstract Data Types Preconditions, Postconditions ADT Examples Data Types Data is stored in a computer as a sequence of binary digits:
More informationList Processing Patterns and List Comprehension
List Processing Patterns and List Comprehension Review: Lists Summary of what we know about lists. A list is a sequence type (like strings and tuples), but that differently from them is mutable (it can
More informationSTA141C: Big Data & High Performance Statistical Computing
STA141C: Big Data & High Performance Statistical Computing Lecture 1: Python programming (1) Cho-Jui Hsieh UC Davis April 4, 2017 Python Python is a scripting language: Non-scripting language (C++. java):
More informationData Visualization (DSC 530/CIS )
Data Visualization (DSC 530/CIS 602-01) JavaScript Dr. David Koop Quiz Given the following HTML, what is the selector for the first div? the super Bowl
More informationShort Answer Questions (40 points)
CS 1112 Fall 2017 Test 2 Page 1 of 6 Short Answer Questions (40 points) 1. TRUE FALSE You have very legibly printed your name and email id below. Name = EMAILD = 2. TRUE FALSE On my honor, I pledge that
More informationCS 2316 Exam 3. Practice. Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score.
CS 2316 Exam 3 Practice Name (print clearly): T-Square ID (gtg, gth, msmith3, etc): Section (e.g., B1): Signature: Failure to properly fill in the information on this page will result in a deduction of
More informationUNIVERSITY OF TORONTO SCARBOROUGH. Fall 2015 EXAMINATIONS. CSC A20H Duration 3 hours. No Aids Allowed
Student Number: Last Name: First Name: UNIVERSITY OF TORONTO SCARBOROUGH Fall 2015 EXAMINATIONS CSC A20H Duration 3 hours No Aids Allowed Do not turn this page until you have received the signal to start.
More informationCSE 115. Introduction to Computer Science I
CSE 115 Introduction to Computer Science I Road map Review exercises dictionaries (key-value mappings) exercises key-value mappings name > phone number person number > student record driver license > driving
More informationFunctions. Genome 559: Introduction to Statistical and Computational Genomics Elhanan Borenstein
Functions Genome 559: Introduction to Statistical and Computational Genomics Elhanan Borenstein What are we missing? A quick review A way to generalized procedures A way to store and handle complex data
More informationPyCodeConf What makes Python Awesome? by Raymond
PyCodeConf 2011 What makes Python Awesome? by Raymond Hettinger @raymondh Context for Success License Commercial Distributions Zen Community Repository of Modules (PyPi) Killer Apps and Success Stores
More informationSenthil Kumaran S
Senthil Kumaran S http://www.stylesen.org/ Agenda History Basics Control Flow Functions Modules History What is Python? Python is a general purpose, object-oriented, high level, interpreted language Created
More informationStudent Database Challenge Problem
Student Database Challenge Problem For this challenge problem, we will create a small database of user information. The python code we write will be able to add new data to the database, save it to a file,
More informationCSE 160 Winter 2016: Final Exam
Name: Sample Solution Email address (UW NetID): CSE 160 Winter 2016: Final Exam (closed book, closed notes, no calculators) Instructions: This exam is closed book, closed notes. You have 50 minutes to
More informationChapter 8 SETS AND DICTIONARIES
Chapter 8 SETS AND DICTIONARIES Chapter Goals To build and use a set container To learn common set operations for processing data To build and use a dictionary container To work with a dictionary for table
More informationTableau Advanced Training. Student Guide April x. For Evaluation Only
Tableau Advanced Training Student Guide www.datarevelations.com 914.945.0567 April 2017 10.x Contents A. Warm Up 1 Bar Chart Colored by Profit 1 Salary Curve 2 2015 v s. 2014 Sales 3 VII. Programmatic
More informationDraft. Students Table. FName LName StudentID College Year. Justin Ennen Science Senior. Dan Bass Management Junior
Chapter 6 Introduction to SQL 6.1 What is a SQL? When would I use it? SQL stands for Structured Query Language. It is a language used mainly for talking to database servers. It s main feature divisions
More informationFinishing Regular Expressions & XML / Web Scraping
Finishing Regular Expressions & XML / Web Scraping April 7 th 2016 CSCI 0931 - Intro. to Comp. for the Humanities and Social Sciences 1 Today Iterators Do ACT 3-2 Finish Regular Expressions XML Parsing
More informationMore Functions. CS 1111 Introduction to Programming. Spring 2019
More Functions CS 1111 Introduction to Programming Spring 2019 [The Coder s Apprentice,, 8-8.3] Based in part on Agnostic Programming: Learning to Design and Test Basic Programming Algorithms by Kinga
More informationCS2304: Python for Java Programmers. CS2304: Sequences and Collections
CS2304: Sequences and Collections Sequences In Python A sequence type in python supports: The in membership operator. The len() function. Slicing like we saw with strings, s[1:3]. And is iterable (for
More informationSequences and Loops. Indices: accessing characters in a string. Old friend: isvowel. Motivation: How to count the number of vowels in a word?
Motivation: How to count the number of vowels in a word? Sequences and Loops o You re given words like 'boston', 'wellesley', 'needham', 'lynn', etc. o Tasks: o count the number of vowels in a word. o
More informationChapter 1. Data types. Data types. In this chapter you will: learn about data types. learn about tuples, lists and dictionaries
Chapter 1 Data types In this chapter you will: learn about data types learn about tuples, lists and dictionaries make a magic card trick app. Data types In Python Basics you were introduced to strings
More informationCS251 Programming Languages Handout # 29 Prof. Lyn Turbak March 7, 2007 Wellesley College
CS5 Programming Languages Handout # 9 Prof. Lyn Turbak March, 00 Wellesley College Postfix: A Simple Stack Language Several exercises and examples in this course will involve the Postfix mini-language.
More informationChapter 6. Files and Exceptions I
Chapter 6 Files and Exceptions I What is a file? a file is a collection of data that is stored on secondary storage like a disk or a thumb drive accessing a file means establishing a connection between
More informationCSc 110, Spring Lecture 28: Sets and Dictionaries. Adapted from slides by Marty Stepp and Stuart Reges
CSc 110, Spring 2017 Lecture 28: Sets and Dictionaries Adapted from slides by Marty Stepp and Stuart Reges 1 Mountain peak Write a program that reads elevation data from a file, draws it on a DrawingPanel
More informationเพ มภาพตามเน อหาของแต ละบท. MS-Access. by Asst. Prof. Wassanaa Naiyapo adapted into English by Dr. Prakarn Unachak IT AND MODERN LIFE
เพ มภาพตามเน อหาของแต ละบท MS-Access by Asst. Prof. Wassanaa Naiyapo adapted into English by Dr. Prakarn Unachak 204100 IT AND MODERN LIFE MS-Access 2016 7.1 Database Basics & Table 7.2 Form 7.3 Query
More informationPython Review IPRE
Python Review 2 Jay Summet 2005-12-31 IPRE Outline Compound Data Types: Strings, Tuples, Lists & Dictionaries Immutable types: Strings Tuples Accessing Elements Cloning Slices Mutable Types: Lists Dictionaries
More informationLow-Fi Prototyping & Pilot Usability Testing
Dan Yu Simon Kim Alex Wang Dazzle Low-Fi Prototyping & Pilot Usability Testing Lena Hong Overview of Low-Fi Prototyping Value proposition and mission statement. Narrowed down designs to target mobile platform.
More informationCS 2316 Individual Homework 4 Greedy Scheduler (Part I) Due: Wednesday, September 18th, before 11:55 PM Out of 100 points
CS 2316 Individual Homework 4 Greedy Scheduler (Part I) Due: Wednesday, September 18th, before 11:55 PM Out of 100 points Files to submit: 1. HW4.py This is an INDIVIDUAL assignment! Collaboration at a
More informationData Management Project Using Software to Carry Out Data Analysis Tasks
Data Management Project Using Software to Carry Out Data Analysis Tasks This activity involves two parts: Part A deals with finding values for: Mean, Median, Mode, Range, Standard Deviation, Max and Min
More informationYour (printed!) Name: CS 1803 Exam 2. Grading TA / Section: Monday, Oct 25th, 2010
Your (printed!) Name: CS 1803 Exam 2 Grading TA / Section: Monday, Oct 25th, 2010 INTEGRITY: By taking this exam, you pledge that this is your work and you have neither given nor received inappropriate
More information1. Basic Steps for Data Analysis Data Editor. 2.4.To create a new SPSS file
1 SPSS Guide 2009 Content 1. Basic Steps for Data Analysis. 3 2. Data Editor. 2.4.To create a new SPSS file 3 4 3. Data Analysis/ Frequencies. 5 4. Recoding the variable into classes.. 5 5. Data Analysis/
More informationAbstract Data Types Chapter 1
Abstract Data Types Chapter 1 Part Two Bags A bag is a basic container like a shopping bag that can be used to store collections. There are several variations: simple bag grab bag counting bag 2 Bag ADT
More informationLecture 21. Chapter 12 More Python Containers
Lecture 21 Chapter 12 More Python Containers 12.1 Two Familiar Containers: list and tuple 12.2 Dictionaries 12.3 Containers of containers 12.4 Set and Frozenset 12.5 Arrays Chapter 12 More Python Containers
More information9/19/12. Why Study Discrete Math? What is discrete? Sets (Rosen, Chapter 2) can be described by discrete math TOPICS
What is discrete? Sets (Rosen, Chapter 2) TOPICS Discrete math Set Definition Set Operations Tuples Consisting of distinct or unconnected elements, not continuous (calculus) Helps us in Computer Science
More informationThe Pyth Language. Administrivia
Administrivia The Pyth Language Lecture 5 Please make sure you have registered your team, created SSH keys as indicated on the admin page, and also have electronically registered with us as well. Prof.
More informationLecture 7. Scientific Computation
Lecture 7 Scientific Computation for-loops: Beyond Sequences Work on iterable objects Object with an ordered collection of data This includes sequences But also much more Examples: Text Files (built-in)
More informationData Structures. Dictionaries - stores a series of unsorted key/value pairs that are indexed using the keys and return the value.
Data Structures Lists - stores a series of ordered mutable items Tuples - stores a series of ordered immutable items [not commonly used] Sets - stores a series of mutable or immutable(frozen) unsorted
More informationCollections. Michael Ernst CSE 190p University of Washington
Collections Michael Ernst CSE 190p University of Washington Needed for Homework 4 (social networking assignment) Collections: lists, sets, dictionaries Sorting Graphs Outline for today Collections (built-in
More informationSequences and Loops. Indices: accessing characters in a string. Old friend: isvowel. Motivation: How to count the number of vowels in a word?
Motivation: How to count the number of vowels in a word? Sequences and Loops o You re given words like 'Boston', 'Wellesley', 'abracadabra', 'bureaucracies', etc. o Tasks: o count the number of vowels
More informationComputer Science & Engineering 120 Learning to Code
Computer Science & Engineering 120 Learning to Code Introduction to Data Christopher M. Bourke cbourke@cse.unl.edu Part I: Working With Data Topic Overview Data Data Formats Data Operations Introduction
More informationCS 234 Python Review Part 2
CS 234 Python Review Part 2 Recap import function: define, return boolean, conditional, branching loop: for, range, while file: open, close, readlines string: split Classes Define blueprint for a custom
More informationAccess. Basics PRESENTED BY THE TECHNOLOGY TRAINERS OF THE MONROE COUNTY LIBRARY SYSTEM
Access 2010 Basics PRESENTED BY THE TECHNOLOGY TRAINERS OF THE MONROE COUNTY LIBRARY SYSTEM EMAIL: TRAININGLAB@MONROE.LIB.MI.US MONROE COUNTY LIBRARY SYSTEM 734-241-5770 840 SOUTH ROESSLER STREET MONROE,
More informationRelational Algebra Part I. CS 377: Database Systems
Relational Algebra Part I CS 377: Database Systems Recap of Last Week ER Model: Design good conceptual models to store information Relational Model: Table representation with structures and constraints
More informationData Abstraction. UW CSE 140 Winter 2013
Data Abstraction UW CSE 140 Winter 2013 What is a program? What is a program? A sequence of instructions to achieve some particular purpose What is a library? A collection of routines that are helpful
More informationCS 2316 Exam 1 Spring 2014
CS 2316 Exam 1 Spring 2014 Name : Grading TA: Integrity: By taking this exam, you pledge that this is your work and you have neither given nor received inappropriate help during the taking of this exam
More informationPython: Short Overview and Recap
Python: Short Overview and Recap Benjamin Roth CIS LMU Benjamin Roth (CIS LMU) Python: Short Overview and Recap 1 / 39 Data Types Object type Example creation Numbers (int, float) 123, 3.14 Strings this
More informationPython allows variables to hold string values, just like any other type (Boolean, int, float). So, the following assignment statements are valid:
1 STRINGS Objectives: How text data is internally represented as a string Accessing individual characters by a positive or negative index String slices Operations on strings: concatenation, comparison,
More informationTouchline Software
Tutorial: Importing Student Data Completing this tutorial will require the limited periodic assistance of the administrator for your student management database system (i.e. Aries, SASI, etc.). General
More informationCS 4460 Intro. to Information Visualization Sep. 18, 2017 John Stasko
Multivariate Visual Representations 1 CS 4460 Intro. to Information Visualization Sep. 18, 2017 John Stasko Learning Objectives For the following visualization techniques/systems, be able to describe each
More informationSorting Fields Changing the Values Line Charts Scatter Graphs Charts Showing Frequency Pie Charts Bar Charts...
Database Guide Contents Introduction... 1 What is RM Easiteach Database?... 1 The Database Toolbar... 2 Reviewing the License Agreement... 3 Using Database... 3 Starting Database... 3 Key Features... 4
More informationCS Homework 4 Employee Ranker. Due: Wednesday, February 8th, before 11:55 PM Out of 100 points. Files to submit: 1. HW4.py.
CS 216 Homework 4 Employee Ranker Due: Wednesday, February 8th, before 11: PM Out of 0 points Files to submit: 1. HW4.py This is an INDIVIDUAL assignment! Collaboration at a reasonable level will not result
More informationMODULE 2 Building and Using Queries
Access-1 Illustrated Microsoft Office 365 and Access 2016 Comprehensive 1st Edition Friedrichsen SOLUTIONS MANUAL Full download at: https://testbankreal.com/download/illustrated-microsoft-office-365-access-
More informationCOMP10001 Foundations of Computing Testing and Debugging
COMP10001 Foundations of Computing Testing and Debugging Semester 1, 2017 Tim Baldwin & Egemen Tanin version: 1103, date: March 30, 2017 2017 The University of Melbourne Reminders Grok Worksheets 8 11
More informationAnswers to Practice Questions
CPSC 301: Computing in the Life Sciences Winter 2015 2016, Term 2 Answers to Practice Questions Question 1 a. Any task that involves animation of many agents is easier implemented in Scratch than Python.
More informationLing 5801: Lecture Notes 9 From Recursive Types to Recursive Functions
Ling 5801: Lecture Notes 9 From Recursive Types to Recursive Functions 1. Programming Functions in Python PDAs use a store to remember current states, process sub-strings, then come back. Programs can
More informationPLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science
PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science APRIL 2016 EXAMINATIONS CSC 108 H1S Instructor(s): Smith and Fairgrieve Duration 3 hours PLEASE HAND IN No Aids Allowed You must earn at
More informationRegistrar Data Instructions
Registrar Data Instructions Registrar data must be submitted for report generation and to confirm the accuracy of reporting. Institutions should carefully review the instructions for descriptions and accepted
More informationMEIN 50010: Python Data Structures
: Python Data Structures Fabian Sievers Higgins Lab, Conway Institute University College Dublin Wednesday, 2017-10-18 Data Structures Stacks, Queues & Deques Structures Data structures are a way of storing
More informationData Structures. Lists, Tuples, Sets, Dictionaries
Data Structures Lists, Tuples, Sets, Dictionaries Collections Programs work with simple values: integers, floats, booleans, strings Often, however, we need to work with collections of values (customers,
More information