close

Вход

Забыли?

вход по аккаунту

Номер п/п;doc

код для вставкиСкачать
CSC326: Assignment 3
Problem 1. The following will go into a le alled prole.py. Create funtion alled prole that deorates
another funtion in the following way:
profile
def foo ( ... ) :
...
What prole will do is reord information about the runtime of the funtion it is deorating using the lok
funtion of the time module. For example:
from time import lok
start = lok()
# do something for a while
duration = lok() - start
Importantly, your implementation of prole should only reord the runtime of a funtion if a global variable
PROFILE_FUNCTIONS has the value True. Regardless of the value of PROFILE_FUNCTIONS, your
deorator should not hange the behavior of the funtion it deorates. That is, the deorated funtion
should aept the same number and kinds of parameters and output the same values as if it were not
deorated. Your deorator must also be general, i.e. I should be able to deorate arbitrary funtions with
prole. See this Wikipedia artile for help on this. Finally, reord the timing results in a global ditionary
PROFILE_RESULTS. The ditionary should map the proled funtion names to their average runtime.
Problem 2. The following will go into a le alled produt.py. Using Funtional Programming Style (without
using any ontrol statement like if-then-else, while loop), reate a funtion named nd_produt to solve the
following problem: Find the greatest produt of ve onseutive digits in the 1000-digit number.
The following will go into a le alled hof.py. Implement your own version of map, redue,
lter Python funtion with the same semantis as the orresponding Python native funtions. Name your
funtions as my_map, my_redue and my_lter.
Problem 3.
The following will go into a le alled popular.py. Write an iterator whih returns words from
a big le, without reading the whole le into memory. Create funtion named nd_popular, whih aept
a text le name as parameter, and print out the list of the ten most popular words (by the number of
ourrenes).
Problem 4.
The following will go into a le alled splitter.py. A sentene splitter is a program apable of
splitting a text into sentenes. The standard set of heuristis for sentene splitting inludes (but isn't limited
to) the following rules:
Problem 5.
Sentene boundaries our at one of "." (periods), "?" or "!", exept that
1
• Periods followed by whitespae followed by a lower ase letter are not sentene boundaries.
• Periods followed by a digit with no intervening whitespae are not sentene boundaries.
• Periods followed by whitespae and then an upper ase letter, but preeded by any of a short list of
titles are not sentene boundaries. Sample titles inlude Mr., Mrs., Dr., and so on.
• Periods internal to a sequene of letters with no adjaent whitespae are not sentene boundaries (for
example, www.aptex.om, or e.g).
• Periods followed by ertain kinds of puntuation (notably omma and more periods) are probably not
sentene boundaries.
Your task here is to write a funtion named split_sentene, that given the name of a text le is able to write
its ontent with eah sentene on a separate line. (Hint using iterators)
Test your program with the following short text:
Mr. Smith bought heapsite.om for 1.5 million dollars, i.e. he paid
a lot for it. Did he mind? Adam Jones Jr. thinks he didn't. In any
ase, this isn't true... Well, with a probability of .9 it isn't.
The result should be:
Mr. Smith bought heapsite.om for 1.5 million dollars, i.e. he paid a lot for it.
Did he mind?
Adam Jones Jr. thinks he didn't.
In any ase, this isn't true...
Well, with a probability of .9 it isn't.
Compress all of your les and save them either as asn3.zip or asn3.tar.gz and
submit the les from a omputer in one of the following labs: GB243, GB251E, or SF2102, or by SSH by
logging on to one of the aformentioned omputers (ug132.eeg - ug180.eeg, ug201.eeg - ug249.eeg).
Submission Instrutions
Submission Command Example
ug132:~% submits326f 3 asn3.zip
2
1/--страниц
Пожаловаться на содержимое документа