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:
PHRASE_FIRST = False
if len(sys.argv) == 2 and sys.argv[1] == "english":
PHRASE_FIRST = True
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 : )
Edit: THIS IS MY TWENTIETH POST!! HOORAY!! wow!
I have been wondering what “for sentence in snippet, phrase:” does.
snippet and phrase are two strings, how does it work?