CSC1018F: Functional Programming (Tutorial)

Slides:



Advertisements
Similar presentations
1 A Censor Class class Censor: def __ init __ badwords=[]): self.badwords = badwords self.replacers = replacers def input_badwords(self,fpath):
Advertisements

Programming Patterns CSC 161: The Art of Programming Prof. Henry Kautz 9/30/2009.
Def f(n): if (n == 0): return else: print(“*”) return f(n-1) f(3)
COMPSCI 210 Semester Tutorial 3: Latches & Exercises from Ch3.
Design a Problem Solution. Making a design In this class we use the words “design”, “pseudocode” and “algorithm” interchangeably These are steps to solve.
Engineering Computing I Chapter 1 – Part B A Tutorial Introduction continued.
CSE (c) S. Tanimoto, 2007 Python Introduction 1 Introduction to Python for Artificial Intelligence Outline: Why Python? Interactive programming,
Python & ModelBuilder. Overview Python/ModelBuilder Concepts – The Geoprocessor – Checking some environment variables – Providing feedback from your model/script.
Recursion. Sum a list of numbers Iterative def sum(L): total = 0 for i in L: total += i return total Recursive def sum(L): if len(L) == 0: return 0 else:
Grep, comm, and uniq. The grep Command The grep command allows a user to search for specific text inside a file. The grep command will find all occurrences.
CSC 4630 Meeting 2 January 22, Filters Definition: A filter is a program that takes a text file as an input and produces a text file as an output.
Recitation 1 Programming for Engineers in Python.
Python & ModelBuilder. Continuing Education Python and ModelBuilder Overview Python/ModelBuilder Concepts –The Geoprocessor –Checking some environment.
Guide to Assignment 3 Programming Tasks 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
CSC1018F: Object Orientation, Exceptions and File Handling Diving into Python Ch. 5&6 Think Like a Comp. Scientist Ch
Programming Training Main Points: - Python Statements - Problems with selections.
Python File Handling. In all the programs you have made so far when program is closed all the data is lost, but what if you want to keep the data to use.
Nutch in a Nutshell Presented by Liew Guo Min Zhao Jin.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 6 Value-Returning.
Text Processing and More about Wrapper Classes
CS 177 Week 4 Recitation Slides Variables, Files and Functions.
Post-Module JavaScript BTM 395: Internet Programming.
9/14/2015BCHB Edwards Introduction to Python BCHB Lecture 4.
Computing Science 1P Large Group Tutorial: Lab Exam & Class Test Simon Gay Department of Computing Science University of Glasgow 2006/07.
1 Chapter 4: Creating Simple Queries 4.1 Introduction to the Query Task 4.2 Selecting Columns and Filtering Rows 4.3 Creating New Columns with an Expression.
READING AND WRITING FILES. READING AND WRITING FILES SEQUENTIALLY  Two ways to read and write files  Sequentially and RA (Random Access  Sequential.
1 Xdefinition ® Václav Trojan Prague June
Guide to Assignment 3 and 4 Programming Tasks 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas.
CSC1018F: Regular Expressions (Tutorial) Diving into Python Ch. 7 Number Systems.
Python – May 16 Recap lab Simple string tokenizing Random numbers Tomorrow: –multidimensional array (list of list) –Exceptions.
PYTHON FUNCTIONS. What you should already know Example: f(x) = 2 * x f(3) = 6 f(3)  using f() 3 is the x input parameter 6 is the output of f(3)
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
CompSci 101 Introduction to Computer Science March 24, 2016 Prof. Rodger compsci 101, spring
Introduction to Python Lesson 2a Print and Types.
Functional Programming in Python Abhishek Dasgupta Indian Institute of Science Education and Research, Kolkata.
DEVRY ACCT 553 W EEK 4 Y OU D ECIDE Check this A+ tutorial guideline at For more classes.
DEVRY CIS 336 W EEK 7 G ROUP P ROJECT T ASK 5 Check this A+ tutorial guideline at
Lesson 06: Functions Class Participation: Class Chat:
Main Points: - Python Statements - Problems with selections.
String Methods Programming Guides.
Computer Science A-level
Introduction to Programming
CSc 110, Autumn 2017 Lecture 19: While loops and File Input
CSC1018F: Regular Expressions
CSC 458– Predictive Analytics I, Fall 2017, Intro. To Python
Embedded Software Development with Python and the Raspberry Pi
CSC1018F: Functional Programming
CompSci 101 Introduction to Computer Science
Another problem to solve…

Another problem to solve…
CSC 458– Predictive Analytics I, Fall 2018, Intro. To Python
Map Reduce Workshop Monday November 12th, 2012
Lesson 06: Functions Class Chat: Attendance: Participation
CSC1018F: Intermediate Python
Writing Functions( ) (Part 4)
CompSci 101 Introduction to Computer Science
CSC1018F: Object Orientation, Exceptions and File Handling (Tutorial)
National Central University, Taiwan
General Computer Science for Engineers CISC 106 Lecture 03
Hint idea 2 Split into shorter tasks like this.
The Python interpreter
Another problem to solve…
Mealy and Moore Machines
Simplifying Expressions
Python Basics. Topics Features How does Python work Basic Features I/O in Python Operators Control Statements Function/Scope of variables OOP Concepts.
CHECKLIST Example text
Computer Science A-level
Challenge Guide Grade Code Type Slides
Factorization by identity a3 + b3.
Presentation transcript:

CSC1018F: Functional Programming (Tutorial) Diving into Python Ch. 16

Revision Exercise You are tasked with coding an “anonymization” program. This replaces names with initials in order to hide identity: To begin, read in a list of names from a file “idprotect.txt”, which contains names in the form: “Firstname” and also “Firstname Surname” on separate lines The main text should be read in from “plaintext.txt” and all occurrences of idprotect names replaced with their corresponding initial. Thus “John” becomes “J.” and “John Smith” becomes “J. S.” The final anonymous text should be output to the file “anontext.txt” Do this using regular expressions, maps and filters, where appropriate

Revision Solution def anonCheck(checkList, checkWord): if checkWord in checkList: return checkWord[0] + "." else: return checkWord def anonymize(): … # Read in and split up the input files idL = idf.read().split() sourceL = sourcef.read().split() dest = " ".join([anonCheck(namesL, word) for word in sourceL]) destf.write(dest) # close all files