{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

cps6-110901Handout

cps6-110901Handout - Announcements CompSci 6 Introduction...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CompSci 6 Introduction to Computer Science September 1, 2011 Prof. Rodger compsci 6 fall 2011 1 Announcements Read for next time Chap. 2 Reading Quiz on Blackboard – Due before class next time Assignment 1 out – due Sept 5! (not Python) Labs start today! – Finish installing software for course – Problem solving compsci 6 fall 2011 2 Word Cloud from last time How do we build a world cloud? compsci 6 fall 2011 3 Focus on Simpler Problems How many words in a file? – What is a file? – What is a word? – How do we count the words How many unique words are in a file? – How is this problem different? compsci 6 fall 2011 4
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Python Code to solve this def countWords(filename): file = open(filename) str = file.read() words = str.split() unique = set(words) print "filename: ", filename print "total # words = ",len(words) print "unique # words = ",len(unique) countWords(‘romeo.txt') filename: romeo.txt total # words = 25788 unique # words = 6394 OUTPUT: Questions?
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}