2018-05-18

posted May 18, 2018, 6:21 AM by Konstantinovich Samuel   [ updated May 18, 2018, 9:56 AM ]
Summer Opportunities: July 5th - 24th (Discuss In Class)

Goal : Inverting a dictionary:


DO NOW:
Your goal is to convert a dictionary such that the keys become values and the values become keys.
e.g.
 { 1:2 , 3:4, 9:13}   returns a new dictionary:  { 2:1, 4:3, 13:9}

What problems can arise with this process? 
How can we overcome them?

def invertDict( d ) :
    #return a new dictionary 
    #such that the key/value pairs are reversed






This should exhibit the list behavior we discussed:

invertDict( { 1:2 , 3:4, 9:13} )  
   returns a new dictionary:  { 2:[1], 4:[3], 13:[9]}

invertDict( { 1:2 , 3:2, 9:13} )  
   returns a new dictionary:  { 2:[1,3], 13:[9]}




New Concepts:

sorted( list ) -> returns a copy of the list in order

This is useful if you want to loop through a dictionary in a specific order.

#print key/value pairs in increasing order of key
for k in sorted(d.keys() ) :
   print k,d[k]



GOALS:
Complete the website by Monday. 
-All stats you already were tasked with.
-For your 250 most common words:

If there are multiple words that are ranked at the same place, then the next number must be increased:
Think:  When two people tied for 1st place, then the next best person is 3rd place.
e.g.
0 ['the']  400
1 ['a']  390
2 ['of','an'] 340
4 ['to'] 300              #NOTICE that it starts at 4
5 ['hat','cat','bat'] 200
8 ['rat'] 100             #notice that it starts at 8


-Make it choose between the 3 books attached to this post. (They will be attached by the end of the day if not now)
-Have each book display a different style and an appropriate image of the book.



ċ
alice.txt
(141k)
Konstantinovich Samuel,
May 18, 2018, 9:57 AM
ċ
frank.txt
(410k)
Konstantinovich Samuel,
May 18, 2018, 9:57 AM
ċ
war.txt
(338k)
Konstantinovich Samuel,
May 18, 2018, 9:57 AM
ċ
warsmall.txt
(2k)
Konstantinovich Samuel,
May 18, 2018, 9:33 AM
Comments