Lesson 41

Oh, wow, Exercise 41. This is great. The code is complicated and I’m still working through it, with gems like:

for sentence in snippet, phrase:
result = sentence[:]

Wow-ee, why is there a colon between the two brackets!
EDIT: This was a CSQ! Here’s what Zed sez:

What does result = sentence[:] do?
That’s a Python way of copying a list. You’re using the list slice syntax [:] to effectively make a slice from the very first element to the very last one.

Also, don’t forget this lil guy:

if len(sys.argv) == 2 and sys.argv[1] == "english":

argv is used to import a file, so I can only guess that it is related to the url that the module urlopen imports. the len operation is easy enough to parse, but I don’t really know why sys is in there. [Edit: duh-doy, sys is just the imported module and sys.argv calls it.] The rest of it, honestly, I have not much idea about the rest of it other than the fact that we’re using some Boolean conditionals.

At any rate, while some of the code is confusing, it became significantly less so once I ran oop_test.py. It’s a test! As in, guess the right answer test! It scrapes the text of this learn code the hard way list of words to make up class names in order to ask what the relation is amongst all cited.

I am going to spend some time with this! The test itself is enjoyable to run. And THEN I shall try to really scrape some understanding of the code into my noggin : )



One thought on “Lesson 41

  1. I have been wondering what “for sentence in snippet, phrase:” does.
    snippet and phrase are two strings, how does it work?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s