# Python Documentation

## Classes

[**State**](https://kgisl.gitbook.io/lab3003/docs/state): enum class to represent possible cell states

[**Board**](https://kgisl.gitbook.io/lab3003/docs/board): Board class to represent the game board

[**Point**](https://kgisl.gitbook.io/lab3003/docs/point): Represents a point in 2-D space.\
attributes: x, y

[**Rectangle**](https://kgisl.gitbook.io/lab3003/docs/rectangle): Represents a rectangle.\
attributes: width, height, corner.

[**Card**](https://kgisl.gitbook.io/lab3003/docs/card): Represents a standard playing card.\
Attributes: suit: integer 0-3 rank: integer 1-13

[**Deck**](https://kgisl.gitbook.io/lab3003/docs/deck): Represents a deck of cards.\
Attributes: cards: list of Card objects.

[**Hand**](https://kgisl.gitbook.io/lab3003/docs/hand): Represents a hand of playing cards.

[**Time**](https://kgisl.gitbook.io/lab3003/docs/time): Represents the time of day.\
attributes: hour, minute, second

[**Markov**](https://kgisl.gitbook.io/lab3003/docs/markov): Encapsulates the statistical summary of a text.

[**Point**](https://kgisl.gitbook.io/lab3003/docs/point): Represents a point in 2-D space.\
attributes: x, y

[**Test**](https://kgisl.gitbook.io/lab3003/docs/test):

[**Time**](https://kgisl.gitbook.io/lab3003/docs/time): Represents the time of day.\
attributes: hour, minute, second

[**PokerHand**](https://kgisl.gitbook.io/lab3003/docs/pokerhand): Represents a poker hand.

[**LinearMap**](https://kgisl.gitbook.io/lab3003/docs/linearmap): A simple implementation of a map using a list of tuples where each tuple is a key-value pair.

[**BetterMap**](https://kgisl.gitbook.io/lab3003/docs/bettermap): A faster implementation of a map using a list of LinearMaps and the built-in function hash() to determine which LinearMap to put each key into.

[**HashMap**](https://kgisl.gitbook.io/lab3003/docs/hashmap): An implementation of a hashtable using a BetterMap that grows so that the number of items never exceeds the number of LinearMaps.\
The amortized cost of add should be O(1) provided that the implementation of sum in resize is linear.

[**Circle**](https://kgisl.gitbook.io/lab3003/docs/circle): Represents a circle.\
Attributes: center, radius

[**Kangaroo**](https://kgisl.gitbook.io/lab3003/docs/kangaroo): A Kangaroo is a marsupial.

[**Hist**](https://kgisl.gitbook.io/lab3003/docs/hist): A map from each item (x) to its frequency.

[**PokerHand**](https://kgisl.gitbook.io/lab3003/docs/pokerhand): Represents a poker hand.

[**PokerDeck**](https://kgisl.gitbook.io/lab3003/docs/pokerdeck): Represents a deck of cards that can deal poker hands.

[**Markov**](https://kgisl.gitbook.io/lab3003/docs/markov): Encapsulates the statistical summary of a text.

[**Time**](https://kgisl.gitbook.io/lab3003/docs/time): Represents the time of day.\
attributes: hour, minute, second

[**Kangaroo**](https://kgisl.gitbook.io/lab3003/docs/kangaroo): A Kangaroo is a marsupial.

## Functions

### fprint

My own function source code inspection function Filters out any print statements and input statements

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| fname |             |         |

### divideTwo

function which takes a list and returns two halves

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| al   |             |         |

### merge

merge generates a new sorted list containing all elements contained in both sorted lists

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| A    |             |         |
| B    |             |         |

### mergesort

sorts the list using the mergesort algorithm

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| alist |             |         |

### fprint

In IPython, you have the very convenient "func"?? which will inspect the source code (<http://j.mp/inspectThis)\\>
My own function source code inspection function Filters out any print statements and input statements

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| fname |             |         |

### selection\_sort

Pure implementation of the selection sort algorithm in Python

#### Parameters

| name        | description                                                                | default |
| ----------- | -------------------------------------------------------------------------- | ------- |
| collection: | some mutable ordered collection with heterogeneous comparable items inside |         |
| collection  |                                                                            |         |

### swap

swap two elements in a list

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| alist |             |         |
| ai    |             |         |
| bi    |             |         |

### min\_index

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| alist |             |         |
| i     |             |         |

### print\_history

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| hlist |             |         |

### selectsort

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| alist |             |         |

### selectsortf

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| alist |             |         |

### selectsortc

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| alist |             |         |

### selectsortd

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| alist |             |         |

### min\_index\_c

function returns the index of the minimum value in the sublist alist\[i:]

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| alist |             |         |
| i     |             |         |

### circulate

Authors: **kgashok**

circulate between three variables, three times

#### Parameters

| name | description  | default |
| ---- | ------------ | ------- |
| a    | is a integer |         |
| b    | is a integer |         |
| c    | is a integer |         |

### circulate\_list

Authors: **kgashok**

circulate 'n' elements in a list, n times

#### Parameters

| name  | description               | default |
| ----- | ------------------------- | ------- |
| alist | contains the 'n' elements |         |

### is\_palindrome

Authors: **kgashok**

check whether a sequence is palindromic using unpacking

#### Parameters

| name | description                            | default |
| ---- | -------------------------------------- | ------- |
| aseq | is a sequence, for e.g. string or list |         |

### is\_palindrome\_rec

Authors: **kgashok**

check for palindrome using unpacking, recursively

#### Parameters

| name | description                               | default |
| ---- | ----------------------------------------- | ------- |
| aseq | is a sequence of elements, string or list |         |

### is\_palindrome\_rec\_slice

Authors: **kgashok**

check for palindrome using slicing, recursively

#### Parameters

| name  | description                               | default |
| ----- | ----------------------------------------- | ------- |
| aseq  | is a sequence of elements, string or list |         |
| first | is first element in seq                   | None    |
| last  | is last element in seq                    | None    |

### moveTower

#### Parameters

| name     | description | default |
| -------- | ----------- | ------- |
| height   |             |         |
| fromPole |             |         |
| toPole   |             |         |
| withPole |             |         |

### moveDisk

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| disk |             |         |
| fp   |             |         |
| tp   |             |         |

### get\_addresses

#### Parameters

| name    | description | default |
| ------- | ----------- | ------- |
| anchors |             |         |

### printURLs

#### Parameters

| name    | description | default |
| ------- | ----------- | ------- |
| url     |             |         |
| anchors |             |         |
| f       |             | None    |

### googleSearch

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| query |             |         |

### googlesearch

#### Parameters

| name      | description | default |
| --------- | ----------- | ------- |
| searchfor |             |         |

### mergesort

#### Parameters

| name    | description | default |
| ------- | ----------- | ------- |
| alist   |             |         |
| verbose |             | False   |

### mergesort2

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| w    |             |         |

### printlist

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| alist |             |         |

### mergesort

Authors: **kgashok**

iterative mergesort implementation

#### Parameters

| name   | description                        | default |
| ------ | ---------------------------------- | ------- |
| series | is a sequence of unsorted elements |         |

### calculateGrade

#### Parameters

| name       | description | default |
| ---------- | ----------- | ------- |
| score      |             |         |
| gradeChart |             |         |

### classAverage

#### Parameters

| name   | description | default |
| ------ | ----------- | ------- |
| scores |             |         |
| gc     |             |         |

### test\_random\_lists

Generates 20 lists of random sizes within the range -5, 10, inclusive. Modify these as per your choice

### qsort\_one\_liner

Authors: **kgashok**

function implements qsort algorithm in recursive mode

#### Parameters

| name  | description                     | default |
| ----- | ------------------------------- | ------- |
| array | is list of numbers to be sorted |         |

### qsort

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| L    |             |         |

### binary\_search

Authors: **kgashok**

function implements binary search algorithm using slicing

#### Parameters

| name  | description                          | default |
| ----- | ------------------------------------ | ------- |
| alist | is list of numbers to be searched    |         |
| token | is the number to be find in the list |         |

### main

### askForPlayerMove

Asks the player for a move. Returns (fromTower, toTower).

#### Parameters

| name   | description | default |
| ------ | ----------- | ------- |
| towers |             |         |

### displayTowers

Display the current state.

#### Parameters

| name   | description | default |
| ------ | ----------- | ------- |
| towers |             |         |

### displayDisk

Display a disk of the given width. A width of 0 means no disk.

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| width |             |         |

### calculate\_grade

Authors: **kgashok**

calculate the grade given a score and a grading chart.

#### Parameters

| name       | description                | default |
| ---------- | -------------------------- | ------- |
| score      | individual student's score |         |
| gradeChart | list of tuples             |         |

### class\_average

Authors: **kgashok**

returns the average grade for the entire class

#### Parameters

| name   | description            | default |
| ------ | ---------------------- | ------- |
| scores | list of student scores |         |
| gc     | list of tuples         |         |

### test\_life\_the\_universe\_and\_everything

a simple example to start you off

### getOutBoundURLs

Authors: **kgashok**

<http://www.w3.org/TR/html5/text-level-semantics.html#the-a-element> anchors contains all \<a> tag elements from the HTML content. Iterate through the list of anchors and build list containing the href addresses whenever it is available.

#### Parameters

| name    | description | default |
| ------- | ----------- | ------- |
| anchors |             |         |

### getOutBoundHttpURLs

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| alist |             |         |

### generateBanner

#### Parameters

| name          | description | default |
| ------------- | ----------- | ------- |
| url           |             |         |
| anchorCount   |             |         |
| outBoundCount |             |         |
| linkCount     |             |         |

### printURLs

Print only those addresses that start with 'https' from valid anchors if 'f'ilename is valid, write extracted URLs to file as well

#### Parameters

| name    | description | default |
| ------- | ----------- | ------- |
| url     |             |         |
| anchors |             |         |
| f       |             | None    |

### sequence\_gen

generate the Lucas Sequence and return upto n elements in a list and ref: <https://cyber-dojo.org/kata/edit/s4Z3PL>

#### Parameters

| name   | description | default |
| ------ | ----------- | ------- |
| number |             |         |

### sequence\_gen\_alt

Authors: **kgashok**

generate the Lucas sequence using another 3 element list

#### Parameters

| name   | description | default |
| ------ | ----------- | ------- |
| number | is an int   |         |

### test\_for\_three\_elements

### test\_for\_five\_elements

### test\_for\_big\_numbers

### getOutBoundURLs

#### Parameters

| name    | description | default |
| ------- | ----------- | ------- |
| a\_tags |             |         |

### generateBanner

#### Parameters

| name        | description | default |
| ----------- | ----------- | ------- |
| url         |             |         |
| anchorCount |             |         |
| linkCount   |             |         |

### printURLs

#### Parameters

| name    | description | default |
| ------- | ----------- | ------- |
| url     |             |         |
| anchors |             |         |
| f       |             | None    |

### getOutBoundURLs2

#### Parameters

| name    | description | default |
| ------- | ----------- | ------- |
| anchors |             |         |

### getOutBoundHttpURLs

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| alist |             |         |

### swap\_func

Authors: **kgashok**

swap the contents of a and b

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| a    | is global   |         |
| b    | is global   |         |

### distance\_between

Authors: **kgashok**

Computes the distance between two Point objects.

#### Parameters

| name   | description | default |
| ------ | ----------- | ------- |
| pointA | is a tuple  |         |
| pointB | is a tuple  |         |

### test\_random\_lists

Generates 20 lists of random sizes within the range - 5, 10, inclusive.Modify these as per your choice

### missing\_plane

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| alist |             |         |

### print\_point

Print a Point object in human-readable format.

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| p    |             |         |

### find\_center

Returns a Point at the center of a Rectangle.\
rect: Rectangle\
returns: new Point

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| rect |             |         |

### grow\_rectangle

Modifies the Rectangle by adding to its width and height.\
rect: Rectangle object. dwidth: change in width (can be negative). dheight: change in height (can be negative).

#### Parameters

| name    | description | default |
| ------- | ----------- | ------- |
| rect    |             |         |
| dwidth  |             |         |
| dheight |             |         |

### main

### factorial

Computes factorial of n recursively.

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| n    |             |         |

### estimate\_pi

Computes an estimate of pi.\
Algorithm due to Srinivasa Ramanujan, from <http://en.wikipedia.org/wiki/Pi>

### make\_word\_dict

Read the words in words.txt and return a dictionary that contains the words as keys

### rotate\_pairs

Prints all words that can be generated by rotating word.\
word: string word\_dict: dictionary with words as keys

#### Parameters

| name       | description | default |
| ---------- | ----------- | ------- |
| word       |             |         |
| word\_dict |             |         |

### str\_fill

Returns i as a string with at least n digits.\
i: int n: int length\
returns: string

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| i    |             |         |
| n    |             |         |

### are\_reversed

Checks if i and j are the reverse of each other.\
i: int j: int\
returns:bool

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| i    |             |         |
| j    |             |         |

### num\_instances

Counts the number of palindromic ages.\
Returns the number of times the mother and daughter have palindromic ages in their lives, given the difference in age.\
diff: int difference in ages flag: bool, if True, prints the details

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| diff |             |         |
| flag |             | False   |

### check\_diffs

Finds age differences that satisfy the problem.\
Enumerates the possible differences in age between mother and daughter, and for each difference, counts the number of times over their lives they will have ages that are the reverse of each other.

### walk

Prints the names of all files in dirname and its subdirectories.\
This is the version in the book.\
dirname: string name of directory

#### Parameters

| name    | description | default |
| ------- | ----------- | ------- |
| dirname |             |         |

### walk2

Prints the names of all files in dirname and its subdirectories.\
This is the exercise solution, which uses os.walk.\
dirname: string name of directory

#### Parameters

| name    | description | default |
| ------- | ----------- | ------- |
| dirname |             |         |

### square

Draws a square with sides of the given length.\
Returns the Turtle to the starting position and location.

#### Parameters

| name   | description | default |
| ------ | ----------- | ------- |
| t      |             |         |
| length |             |         |

### polyline

Draws n line segments.\
t: Turtle object n: number of line segments length: length of each segment angle: degrees between segments

#### Parameters

| name   | description | default |
| ------ | ----------- | ------- |
| t      |             |         |
| n      |             |         |
| length |             |         |
| angle  |             |         |

### polygon

Draws a polygon with n sides.\
t: Turtle n: number of sides length: length of each side.

#### Parameters

| name   | description | default |
| ------ | ----------- | ------- |
| t      |             |         |
| n      |             |         |
| length |             |         |

### arc

Draws an arc with the given radius and angle.\
t: Turtle r: radius angle: angle subtended by the arc, in degrees

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| t     |             |         |
| r     |             |         |
| angle |             |         |

### circle

Draws a circle with the given radius.\
t: Turtle r: radius

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| r    |             |         |

### nested\_sum

Computes the total of all numbers in a list of lists.\
t: list of list of numbers\
returns: number

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |

### cumsum

Computes the cumulative sum of the numbers in t.\
t: list of numbers\
returns: list of numbers

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |

### middle

Returns all but the first and last elements of t.\
t: list\
returns: new list

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |

### chop

Removes the first and last elements of t.\
t: list\
returns: None

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |

### is\_sorted

Checks whether a list is sorted.\
t: list\
returns: boolean

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |

### is\_anagram

Checks whether two words are anagrams\
word1: string or list word2: string or list\
returns: boolean

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| word1 |             |         |
| word2 |             |         |

### has\_duplicates

Returns True if any element appears more than once in a sequence.\
s: string or list\
returns: bool

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| s    |             |         |

### main

### teleport

Moves the turtle without drawing a line.\
Postcondition: pen is down\
t: Turtle x: coordinate y: coordinate

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| x    |             |         |
| y    |             |         |

### keypress

Handles the event when a user presses a key.\
Checks if there is a function with the right name; otherwise it prints an error message.\
char: string, letter to draw

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| char |             |         |

### carriage\_return

Moves to the beginning of the next line.

### presser

Returns a function object that executes keypress.\
char: character to draw when the function is executed\
returns: function with no arguments

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| char |             |         |

### find\_defining\_class

Finds and returns the class object that will provide the definition of method\_name (as a string) if it is invoked on obj.\
obj: any python object method\_name: string method name

#### Parameters

| name         | description | default |
| ------------ | ----------- | ------- |
| obj          |             |         |
| method\_name |             |         |

### ackermann

Computes the Ackermann function A(m, n)\
See <http://en.wikipedia.org/wiki/Ackermann\\_function\\>
n, m: non-negative integers

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| m    |             |         |
| n    |             |         |

### make\_word\_dict

Read. the words in words.txt and return a dictionary that contains the words as keys.

### homophones

Checks if words two can be pronounced the same way.\
If either word is not in the pronouncing dictionary, return False\
a, b: strings phonetic: map from words to pronunciation codes

#### Parameters

| name     | description | default |
| -------- | ----------- | ------- |
| a        |             |         |
| b        |             |         |
| phonetic |             |         |

### check\_word

Checks to see if the word has the following property: removing the first letter yields a word with the same pronunciation, and removing the second letter yields a word with the same pronunciation.\
word: string word\_dict: dictionary with words as keys phonetic: map from words to pronunciation codes

#### Parameters

| name       | description | default |
| ---------- | ----------- | ------- |
| word       |             |         |
| word\_dict |             |         |
| phonetic   |             |         |

### walk

Finds the names of all files in dirname and its subdirectories.\
dirname: string name of directory

#### Parameters

| name    | description | default |
| ------- | ----------- | ------- |
| dirname |             |         |

### compute\_checksum

Computes the MD5 checksum of the contents of a file.\
filename: string

#### Parameters

| name     | description | default |
| -------- | ----------- | ------- |
| filename |             |         |

### check\_diff

Computes the difference between the contents of two files.\
name1, name2: string filenames

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| name1 |             |         |
| name2 |             |         |

### pipe

Runs a command in a subprocess.\
cmd: string Unix command\
Returns (res, stat), the output of the subprocess and the exit status.

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| cmd  |             |         |

### compute\_checksums

Computes checksums for all files with the given suffix.\
dirname: string name of directory to search suffix: string suffix to match\
Returns: map from checksum to list of files with that checksum

#### Parameters

| name    | description | default |
| ------- | ----------- | ------- |
| dirname |             |         |
| suffix  |             |         |

### check\_pairs

Checks whether any in a list of files differs from the others.\
names: list of string filenames

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| names |             |         |

### print\_duplicates

Checks for duplicate files.\
Reports any files with the same checksum and checks whether they are, in fact, identical.\
d: map from checksum to list of files with that checksum

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| d    |             |         |

### sed

Reads a source file and writes the destination file.\
In each line, replaces pattern with replace.\
pattern: string replace: string source: string filename dest: string filename

#### Parameters

| name    | description | default |
| ------- | ----------- | ------- |
| pattern |             |         |
| replace |             |         |
| source  |             |         |
| dest    |             |         |

### main

### rotate\_letter

Rotates a letter by n places. Does not change other chars.\
letter: single-letter string n: int\
Returns: single-letter string

#### Parameters

| name   | description | default |
| ------ | ----------- | ------- |
| letter |             |         |
| n      |             |         |

### rotate\_word

Rotates a word by n places.\
word: string n: integer\
Returns: string

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| word |             |         |
| n    |             |         |

### do\_twice

Runs a function twice.\
func: function object arg: argument passed to the function

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| func |             |         |
| arg  |             |         |

### print\_twice

Prints the argument twice.\
arg: anything printable

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| arg  |             |         |

### do\_four

Runs a function four times.\
func: function object arg: argument passed to the function

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| func |             |         |
| arg  |             |         |

### store\_anagrams

Stores the anagrams from a dictionary in a shelf.\
filename: string file name of shelf anagram\_map: dictionary that maps strings to list of anagrams

#### Parameters

| name         | description | default |
| ------------ | ----------- | ------- |
| filename     |             |         |
| anagram\_map |             |         |

### read\_anagrams

Looks up a word in a shelf and returns a list of its anagrams.\
filename: string file name of shelf word: word to look up

#### Parameters

| name     | description | default |
| -------- | ----------- | ------- |
| filename |             |         |
| word     |             |         |

### main

#### Parameters

| name    | description | default    |
| ------- | ----------- | ---------- |
| script  |             |            |
| command |             | "make\_db" |

### interlock

Checks whether a word contains two interleaved words.\
word\_list: list of strings word: string

#### Parameters

| name       | description | default |
| ---------- | ----------- | ------- |
| word\_list |             |         |
| word       |             |         |

### interlock\_general

Checks whether a word contains n interleaved words.\
word\_list: list of strings word: string n: number of interleaved words

#### Parameters

| name       | description | default |
| ---------- | ----------- | ------- |
| word\_list |             |         |
| word       |             |         |
| n          |             | 3       |

### draw\_circle

Draws a circle.\
t: Turtle circle: Circle

#### Parameters

| name   | description | default |
| ------ | ----------- | ------- |
| t      |             |         |
| circle |             |         |

### draw\_rect

Draws a rectangle.\
t: Turtle rect: Rectangle

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| rect |             |         |

### print\_time

Prints a string representation of the time.\
t: Time object

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |

### int\_to\_time

Makes a new Time object.\
seconds: int seconds since midnight.

#### Parameters

| name    | description | default |
| ------- | ----------- | ------- |
| seconds |             |         |

### time\_to\_int

Computes the number of seconds since midnight.\
time: Time object.

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| time |             |         |

### add\_times

Adds two time objects.\
t1, t2: Time\
returns: Time

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t1   |             |         |
| t2   |             |         |

### valid\_time

Checks whether a Time object satisfies the invariants.\
time: Time\
returns: boolean

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| time |             |         |

### main

### petal

Draws a petal using two arcs.\
t: Turtle r: radius of the arcs angle: angle (degrees) that subtends the arcs

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| t     |             |         |
| r     |             |         |
| angle |             |         |

### flower

Draws a flower with n petals.\
t: Turtle n: number of petals r: radius of the arcs angle: angle (degrees) that subtends the arcs

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| t     |             |         |
| n     |             |         |
| r     |             |         |
| angle |             |         |

### move

Move Turtle (t) forward (length) units without leaving a trail. Leaves the pen down.

#### Parameters

| name   | description | default |
| ------ | ----------- | ------- |
| t      |             |         |
| length |             |         |

### main

#### Parameters

| name     | description | default    |
| -------- | ----------- | ---------- |
| script   |             |            |
| filename |             | "emma.txt" |
| n        |             | 100        |
| order    |             | 2          |

### make\_word\_list

Reads lines from a file and builds a list using append.\
returns: list of strings

### in\_bisect

Checks whether a word is in a list using bisection search.\
Precondition: the words in the list are sorted\
word\_list: list of strings word: string

#### Parameters

| name       | description | default |
| ---------- | ----------- | ------- |
| word\_list |             |         |
| word       |             |         |

### in\_bisect\_cheat

Checks whether a word is in a list using bisection search.\
Precondition: the words in the list are sorted\
word\_list: list of strings word: string

#### Parameters

| name       | description | default |
| ---------- | ----------- | ------- |
| word\_list |             |         |
| word       |             |         |

### metathesis\_pairs

Print all pairs of words that differ by swapping two letters.\
d: map from word to list of anagrams

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| d    |             |         |

### word\_distance

Computes the number of differences between two words.\
word1, word2: strings\
Returns: integer

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| word1 |             |         |
| word2 |             |         |

### read\_dictionary

Reads from a file and builds a dictionary that maps from each word to a string that describes its primary pronunciation.\
Secondary pronunciations are added to the dictionary with a number, in parentheses, at the end of the key, so the key for the second pronunciation of "abdominal" is "abdominal(2)".\
filename: string returns: map from string to pronunciation

#### Parameters

| name     | description | default |
| -------- | ----------- | ------- |
| filename |             | "c06d"  |

### structshape

Returns a string that describes the shape of a data structure.\
ds: any Python object\
Returns: string

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| ds   |             |         |

### listrep

Returns a string representation of a list of type strings.\
t: list of strings\
Returns: string

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |

### setrep

Returns a string representation of a set of type strings.\
s: set of strings\
Returns: string

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| s    |             |         |

### append

Adds a new element to a list of type strings.\
Modifies res.\
res: list of type strings typestr: the new type string count: how many of the new type there are\
Returns: None

#### Parameters

| name    | description | default |
| ------- | ----------- | ------- |
| res     |             |         |
| typestr |             |         |
| count   |             |         |

### main

### signature

Returns the signature of this string.\
Signature is a string that contains all of the letters in order.\
s: string

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| s    |             |         |

### all\_anagrams

Finds all anagrams in a list of words.\
filename: string filename of the word list\
Returns: a map from each word to a list of its anagrams.

#### Parameters

| name     | description | default |
| -------- | ----------- | ------- |
| filename |             |         |

### print\_anagram\_sets

Prints the anagram sets in d.\
d: map from words to list of their anagrams

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| d    |             |         |

### print\_anagram\_sets\_in\_order

Prints the anagram sets in d in decreasing order of size.\
d: map from words to list of their anagrams

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| d    |             |         |

### filter\_length

Select only the words in d that have n letters.\
d: map from word to list of anagrams n: integer number of letters\
returns: new map from word to list of anagrams

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| d    |             |         |
| n    |             |         |

### random\_word

Chooses a random word from a histogram.\
The probability of each word is proportional to its frequency.\
hist: map from word to frequency

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| hist |             |         |

### main

### distance\_between\_points

Computes the distance between two Point objects.\
p1: Point p2: Point\
returns: float

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| p1   |             |         |
| p2   |             |         |

### move\_rectangle

Move the Rectangle by modifying its corner object.\
rect: Rectangle object. dx: change in x coordinate (can be negative). dy: change in y coordinate (can be negative).

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| rect |             |         |
| dx   |             |         |
| dy   |             |         |

### move\_rectangle\_copy

Move the Rectangle and return a new Rectangle object.\
rect: Rectangle object. dx: change in x coordinate (can be negative). dy: change in y coordinate (can be negative).\
returns: new Rectangle

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| rect |             |         |
| dx   |             |         |
| dy   |             |         |

### main

### int\_to\_time

Makes a new Time object.\
seconds: int seconds since midnight.

#### Parameters

| name    | description | default |
| ------- | ----------- | ------- |
| seconds |             |         |

### main

### is\_after

Returns True if t1 is after t2; false otherwise.

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t1   |             |         |
| t2   |             |         |

### increment

Adds seconds to a Time object.

#### Parameters

| name    | description | default |
| ------- | ----------- | ------- |
| t1      |             |         |
| seconds |             |         |

### mul\_time

Multiplies a Time object by a factor.

#### Parameters

| name   | description | default |
| ------ | ----------- | ------- |
| t1     |             |         |
| factor |             |         |

### days\_until\_birthday

How long until my next birthday?

#### Parameters

| name     | description | default |
| -------- | ----------- | ------- |
| birthday |             |         |

### double\_day

Compute the day when one person is twice as old as the other.\
b1: datetime birthday of the younger person b2: datetime birthday of the older person

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| b1   |             |         |
| b2   |             |         |

### datetime\_exercises

Exercise solutions.

### main

### make\_word\_list1

Reads lines from a file and builds a list using append.

### make\_word\_list2

Reads lines from a file and builds a list using list +.

### subtract

Returns a set of all keys that appear in d1 but not d2.\
d1, d2: dictionaries

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| d1   |             |         |
| d2   |             |         |

### main

### test\_fun

test function which is used to validate if the custom packge installation worked successfully

### walk

Finds the names of all files in dirname and its subdirectories.\
dirname: string name of directory

#### Parameters

| name    | description | default |
| ------- | ----------- | ------- |
| dirname |             |         |

### compute\_checksum

Computes the MD5 checksum of the contents of a file.\
filename: string

#### Parameters

| name     | description | default |
| -------- | ----------- | ------- |
| filename |             |         |

### check\_diff

Computes the difference between the contents of two files.\
name1, name2: string filenames

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| name1 |             |         |
| name2 |             |         |

### pipe

Runs a command in a subprocess.\
cmd: string Unix command\
Returns (res, stat), the output of the subprocess and the exit status.

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| cmd  |             |         |

### compute\_checksums

Computes checksums for all files with the given suffix.\
dirname: string name of directory to search suffix: string suffix to match\
Returns: map from checksum to list of files with that checksum

#### Parameters

| name    | description | default |
| ------- | ----------- | ------- |
| dirname |             |         |
| suffix  |             |         |

### check\_pairs

Checks whether any in a list of files differs from the others.\
names: list of string filenames

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| names |             |         |

### print\_duplicates

Checks for duplicate files.\
Reports any files with the same checksum and checks whether they are, in fact, identical.\
d: map from checksum to list of files with that checksum

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| d    |             |         |

### process\_file

Makes a histogram that contains the words from a file.\
filename: string skip\_header: boolean, whether to skip the Gutenberg header\
returns: map from each word to the number of times it appears.

#### Parameters

| name         | description | default |
| ------------ | ----------- | ------- |
| filename     |             |         |
| skip\_header |             |         |

### skip\_gutenberg\_header

Reads from fp until it finds the line that ends the header.\
fp: open file object

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| fp   |             |         |

### process\_line

Adds the words in the line to the histogram.\
Modifies hist.\
line: string hist: histogram (map from word to frequency)

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| line |             |         |
| hist |             |         |

### most\_common

Makes a list of word-freq pairs in descending order of frequency.\
hist: map from word to frequency\
returns: list of (frequency, word) pairs

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| hist |             |         |

### print\_most\_common

Prints the most commons words in a histgram and their frequencies.\
hist: histogram (map from word to frequency) num: number of words to print

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| hist |             |         |
| num  |             | 10      |

### subtract

Returns a dictionary with all keys that appear in d1 but not d2.\
d1, d2: dictionaries

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| d1   |             |         |
| d2   |             |         |

### total\_words

Returns the total of the frequencies in a histogram.

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| hist |             |         |

### different\_words

Returns the number of different words in a histogram.

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| hist |             |         |

### random\_word

Chooses a random word from a histogram.\
The probability of each word is proportional to its frequency.

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| hist |             |         |

### main

### first

Returns the first character of a string.

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| word |             |         |

### last

Returns the last of a string.

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| word |             |         |

### middle

Returns all but the first and last characters of a string.

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| word |             |         |

### is\_palindrome

Returns True if word is a palindrome.

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| word |             |         |

### make\_word\_dict

Reads a word list and returns a dictionary.

### is\_reducible

If word is reducible, returns a list of its reducible children.\
Also adds an entry to the memo dictionary.\
A string is reducible if it has at least one child that is reducible. The empty string is also reducible.\
word: string word\_dict: dictionary with words as keys

#### Parameters

| name       | description | default |
| ---------- | ----------- | ------- |
| word       |             |         |
| word\_dict |             |         |

### children

Returns a list of all words that can be formed by removing one letter.\
word: string\
Returns: list of strings

#### Parameters

| name       | description | default |
| ---------- | ----------- | ------- |
| word       |             |         |
| word\_dict |             |         |

### all\_reducible

Checks all words in the word\_dict; returns a list reducible ones.\
word\_dict: dictionary with words as keys

#### Parameters

| name       | description | default |
| ---------- | ----------- | ------- |
| word\_dict |             |         |

### print\_trail

Prints the sequence of words that reduces this word to the empty string.\
If there is more than one choice, it chooses the first.\
word: string

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| word |             |         |

### print\_longest\_words

Finds the longest reducible words and prints them.\
word\_dict: dictionary of valid words

#### Parameters

| name       | description | default |
| ---------- | ----------- | ------- |
| word\_dict |             |         |

### do\_twice

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| f    |             |         |

### do\_four

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| f    |             |         |

### print\_beam

### print\_post

### print\_beams

### print\_posts

### print\_row

### print\_grid

### one\_four\_one

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| f    |             |         |
| g    |             |         |
| h    |             |         |

### print\_plus

### print\_dash

### print\_bar

### print\_space

### print\_end

### nothing

do nothing

### print1beam

### print1post

### print4beams

### print4posts

### print\_row

### print\_grid

### has\_duplicates

Returns True if any element appears more than once in a sequence.\
t: list\
returns: bool

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |

### random\_bdays

Returns a list of integers between 1 and 365, with length n.\
n: int\
returns: list of int

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| n    |             |         |

### count\_matches

Generates a sample of birthdays and counts duplicates.\
num\_students: how many students in the group num\_samples: how many groups to simulate\
returns: int

#### Parameters

| name             | description | default |
| ---------------- | ----------- | ------- |
| num\_students    |             |         |
| num\_simulations |             |         |

### main

Runs the birthday simulation and prints the number of matches.

### main

### is\_triple\_double

Tests if a word contains three consecutive double letters.\
word: string\
returns: bool

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| word |             |         |

### find\_triple\_double

Reads a word list and prints words with triple double letters.

### point\_in\_circle

Checks whether a point lies inside a circle (or on the boundary).\
point: Point object circle: Circle object

#### Parameters

| name   | description | default |
| ------ | ----------- | ------- |
| point  |             |         |
| circle |             |         |

### rect\_in\_circle

Checks whether the corners of a rect fall in/on a circle.\
rect: Rectangle object circle: Circle object

#### Parameters

| name   | description | default |
| ------ | ----------- | ------- |
| rect   |             |         |
| circle |             |         |

### rect\_circle\_overlap

Checks whether any corners of a rect fall in/on a circle.\
rect: Rectangle object circle: Circle object

#### Parameters

| name   | description | default |
| ------ | ----------- | ------- |
| rect   |             |         |
| circle |             |         |

### main

### draw\_spiral

Draws an Archimedian spiral starting at the origin.\
Args: n: how many line segments to draw length: how long each segment is a: how loose the initial spiral starts out (larger is looser) b: how loosly coiled the spiral is (larger is looser)\
<http://en.wikipedia.org/wiki/Spiral>

#### Parameters

| name   | description | default |
| ------ | ----------- | ------- |
| t      |             |         |
| n      |             |         |
| length |             | 3       |
| a      |             | 0.1     |
| b      |             | 0.0002  |

### most\_frequent

Sorts the letters in s in reverse order of frequency.\
s: string\
Returns: list of letters

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| s    |             |         |

### make\_histogram

Make a map from letters to number of times they appear in s.\
s: string\
Returns: map from letter to frequency

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| s    |             |         |

### read\_file

Returns the contents of a file as a string.

#### Parameters

| name     | description | default |
| -------- | ----------- | ------- |
| filename |             |         |

### rank\_freq

Returns a list of (rank, freq) tuples.\
hist: map from word to frequency\
returns: list of (rank, freq) tuples

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| hist |             |         |

### print\_ranks

Prints the rank vs. frequency data.\
hist: map from word to frequency

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| hist |             |         |

### plot\_ranks

Plots frequency vs. rank.\
hist: map from word to frequency scale: string 'linear' or 'log'

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| hist  |             |         |
| scale |             | "log"   |

### main

#### Parameters

| name     | description | default    |
| -------- | ----------- | ---------- |
| script   |             |            |
| filename |             | "emma.txt" |
| flag     |             | "plot"     |

### pipe

Runs a command in a subprocess.\
cmd: string Unix command\
Returns (res, stat), the output of the subprocess and the exit status.

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| cmd  |             |         |

### reverse\_pair

Checks whether a reversed word appears in word\_list.\
word\_list: list of strings word: string

#### Parameters

| name       | description | default |
| ---------- | ----------- | ------- |
| word\_list |             |         |
| word       |             |         |

### fd

#### Parameters

| name   | description | default |
| ------ | ----------- | ------- |
| t      |             |         |
| length |             |         |

### bk

#### Parameters

| name   | description | default |
| ------ | ----------- | ------- |
| t      |             |         |
| length |             |         |

### lt

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| t     |             |         |
| angle |             | 90      |

### rt

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| t     |             |         |
| angle |             | 90      |

### pd

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |

### pu

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |

### fdlt

forward and left

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| t     |             |         |
| n     |             |         |
| angle |             | 90      |

### fdbk

forward and back, ending at the original position

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### skip

lift the pen and move

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### stump

Makes a vertical line and leave the turtle at the top, facing right

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| t     |             |         |
| n     |             |         |
| angle |             | 90      |

### hollow

move the turtle vertically and leave it at the top, facing right

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### post

Makes a vertical line and return to the original position

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### beam

Makes a horizontal line at the given height and return.

#### Parameters

| name   | description | default |
| ------ | ----------- | ------- |
| t      |             |         |
| n      |             |         |
| height |             |         |

### hangman

Makes a vertical line to the given height and a horizontal line at the given height and then return. This is efficient to implement, and turns out to be useful, but it's not so semantically clean.

#### Parameters

| name   | description | default |
| ------ | ----------- | ------- |
| t      |             |         |
| n      |             |         |
| height |             |         |

### diagonal

Makes a diagonal line to the given x, y offsets and return

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| x    |             |         |
| y    |             |         |

### vshape

#### Parameters

| name   | description | default |
| ------ | ----------- | ------- |
| t      |             |         |
| n      |             |         |
| height |             |         |

### bump

Makes a bump with radius n at height\*n

#### Parameters

| name   | description | default |
| ------ | ----------- | ------- |
| t      |             |         |
| n      |             |         |
| height |             |         |

### draw\_a

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### draw\_b

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### draw\_c

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### draw\_d

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### draw\_ef

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### draw\_e

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### draw\_f

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### draw\_g

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### draw\_h

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### draw\_i

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### draw\_j

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### draw\_k

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### draw\_l

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### draw\_n

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### draw\_m

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### draw\_o

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### draw\_p

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### draw\_q

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### draw\_r

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### draw\_s

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### draw\_t

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### draw\_u

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### draw\_v

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### draw\_w

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### draw\_x

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### draw\_v

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### draw\_y

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### draw\_z

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### draw\_

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### main

### draw\_pie

Draws a pie, then moves into position to the right.\
t: Turtle n: number of segments r: length of the radial spokes

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |
| r    |             |         |

### polypie

Draws a pie divided into radial segments.\
t: Turtle n: number of segments r: length of the radial spokes

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |
| r    |             |         |

### isosceles

Draws an icosceles triangle.\
The turtle starts and ends at the peak, facing the middle of the base.\
t: Turtle r: length of the equal legs angle: peak angle in degrees

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| t     |             |         |
| r     |             |         |
| angle |             |         |

### main

#### Parameters

| name     | description | default    |
| -------- | ----------- | ---------- |
| script   |             |            |
| filename |             | "emma.txt" |
| n        |             | 100        |
| order    |             | 2          |

### invert\_dict

Inverts a dictionary, returning a map from val to a list of keys.\
If the mapping key->val appears in d, then in the new dictionary val maps to a list that includes key.\
d: dict\
Returns: dict

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| d    |             |         |

### ackermann

Computes the Ackermann function A(m, n)\
See <http://en.wikipedia.org/wiki/Ackermann\\_function\\>
n, m: non-negative integers

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| m    |             |         |
| n    |             |         |

### main

### int\_to\_time

Makes a new Time object.\
seconds: int seconds since midnight.

#### Parameters

| name    | description | default |
| ------- | ----------- | ------- |
| seconds |             |         |

### main

### sort\_by\_length

Sort a list of words in reverse order by length.\
This is the version in the book; it is stable in the sense that words with the same length appear in the same order\
words: list of strings\
Returns: list of strings

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| words |             |         |

### sort\_by\_length\_random

Sort a list of words in reverse order by length.\
This is the solution to the exercise. It is unstable in the sense that if two words have the same length, their order in the output list is random.\
It works by extending the list of tuples with a column of random numbers; when there is a tie in the first column, the random column determines the output order.\
words: list of strings\
Returns: list of strings

#### Parameters

| name  | description | default |
| ----- | ----------- | ------- |
| words |             |         |

### has\_duplicates

Checks whether any element appears more than once in a sequence.\
Simple version using a for loop.\
t: sequence

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |

### has\_duplicates2

Checks whether any element appears more than once in a sequence.\
Faster version using a set.\
t: sequence

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |

### koch

Draws a koch curve with length n.

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### snowflake

Draws a snowflake (a triangle with a Koch curve for each side).

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| t    |             |         |
| n    |             |         |

### has\_palindrome

Checks if the string representation of i has a palindrome.\
i: integer start: where in the string to start length: length of the palindrome to check for

#### Parameters

| name   | description | default |
| ------ | ----------- | ------- |
| i      |             |         |
| start  |             |         |
| length |             |         |

### check

Checks if the integer (i) has the desired properties.\
i: int

#### Parameters

| name | description | default |
| ---- | ----------- | ------- |
| i    |             |         |

### check\_all

Enumerate the six-digit numbers and print any winners.

### test\_fun2

test function which is used to validate if the custom packge installation worked successfully
