*** scooper has quit (Quit: Leaving) | 11:28 | |
jelkner | Good day, tboimah | 11:47 |
---|---|---|
tboimah | Good morning Jeff | 11:47 |
jelkner | thanks for starting that email exchange yesterday | 11:48 |
jelkner | we need to continue to have discussions like that | 11:48 |
jelkner | we'll have a lot of them when i'm in monrovia next summer! | 11:48 |
jelkner | do you know if you all have any questions for me today? | 11:49 |
jelkner | i have to run off copies of two quizzes for today | 11:49 |
jelkner | so i need to get to the copy machine before it gets too busy | 11:49 |
jelkner | i can stay for the planned 10 minutes | 11:49 |
tboimah | i have one question for you Jeff | 11:49 |
jelkner | but no longer | 11:49 |
jelkner | give it to me | 11:49 |
tboimah | Okay the question is: | 11:50 |
tboimah | t = [[3-i for i in range (3)] for j in range (3)] | 11:50 |
tboimah | s = 0 | 11:50 |
tboimah | for i in range(3): | 11:50 |
tboimah | s += t [i][i] | 11:50 |
tboimah | print(s) | 11:50 |
tboimah | That is a code | 11:50 |
tboimah | that code will give 6 | 11:50 |
jelkner | so you have a nested list comprehension | 11:51 |
tboimah | as the answer i have explain in my own way i get the same 6 but i will | 11:51 |
jelkner | to evaluate it, you need to work from the inside out | 11:51 |
tboimah | also need you to explain | 11:51 |
jelkner | first, you need to evaluate [3-i for in in range(3)] | 11:52 |
jelkner | range(3) returns an iterator that will produce 0, 1, and 2 | 11:52 |
jelkner | so 3 - i for each of those will produce... | 11:52 |
jelkner | [3, 2, 1] | 11:52 |
jelkner | right? | 11:52 |
tboimah | yeah | 11:53 |
jelkner | try it in the REPL | 11:53 |
tboimah | i already try it | 11:53 |
jelkner | ok, next, the for j in range(3) just repeats that 3 times | 11:53 |
tboimah | i just need you to explain | 11:53 |
jelkner | so you get 3 copies | 11:53 |
jelkner | it will look like: | 11:53 |
jelkner | [3, 2, 1], [3, 2, 1], [3, 2, 1]] | 11:54 |
jelkner | oops, i'm missing an [ | 11:54 |
jelkner | in the beginning | 11:54 |
jelkner | it is a nested list | 11:54 |
jelkner | 3 copies of the same [3, 2, 1] list | 11:54 |
jelkner | make sense? | 11:54 |
tboimah | sure | 11:54 |
jelkner | great | 11:55 |
tboimah | so the answer will be six | 11:55 |
jelkner | so no, we evaluate the for loop | 11:55 |
tboimah | because | 11:55 |
jelkner | go ahead | 11:55 |
tboimah | 3 - 0 is 3 | 11:55 |
tboimah | and 3 -1 is 2 | 11:55 |
jelkner | hmmm | 11:56 |
tboimah | 3- 2 is 1 | 11:56 |
jelkner | not exactly | 11:56 |
jelkner | when you see nested lists like this | 11:56 |
tboimah | then explain more | 11:56 |
jelkner | one way to think of it is a a matrix | 11:56 |
jelkner | are you familiar with matrices from math? | 11:56 |
tboimah | yeah | 11:56 |
jelkner | instead of [[3, 2, 1], [3, 2, 1], [3, 2, 1]] | 11:57 |
jelkner | think of it like this: | 11:57 |
jelkner | [[3, 2, 1], | 11:57 |
jelkner | [3, 2, 1], | 11:57 |
jelkner | [3, 2, 1]] | 11:57 |
jelkner | oops, i wanted them to line up | 11:57 |
jelkner | anyway, we have rows and columns | 11:57 |
tboimah | yeah three row and three colums | 11:58 |
jelkner | if we name this matrix m | 11:58 |
jelkner | what value is at m[0][0] ? | 11:58 |
tboimah | 3 | 11:58 |
jelkner | yes! | 11:58 |
jelkner | and m[1][1] ? | 11:58 |
tboimah | will be 2 | 11:58 |
jelkner | exactly! | 11:58 |
jelkner | so this for loop is adding the values along the main diagonal | 11:59 |
jelkner | s = 3 + 2 + 1 | 11:59 |
jelkner | since m[2][2] is 1 | 11:59 |
jelkner | take a look at kevin's email | 12:00 |
jelkner | what you should do now | 12:00 |
jelkner | is make some changes to this code so that it changes the matrix produced | 12:00 |
jelkner | then see if you can predict what will happen | 12:00 |
jelkner | t = [[3+i for i in range (3)] for j in range (3)] | 12:01 |
jelkner | for example | 12:01 |
jelkner | so make it a 4 x 4 matrix | 12:01 |
jelkner | t = [[4-i for i in range (4)] for j in range (4)] | 12:01 |
jelkner | things like that | 12:01 |
jelkner | "play" with the code until it becomes yours | 12:02 |
jelkner | nice question | 12:02 |
jelkner | i have to go | 12:02 |
jelkner | but i'll be back tomorrow | 12:02 |
tboimah | sure thanks | 12:02 |
jelkner | kevin meets with you tomorrow, yes? | 12:03 |
tboimah | yes | 12:03 |
jelkner | he is a great tutor | 12:03 |
jelkner | and you'll have 2 hours with him | 12:03 |
jelkner | okie dokie | 12:03 |
jelkner | talk to you tomorrow... | 12:03 |
tboimah | okay | 12:03 |
tboimah | have a nice day | 12:03 |
jelkner | you too! | 12:04 |
jelkner | ACTION signs off... | 12:04 |
*** jelkner has quit (Quit: Leaving) | 12:04 | |
*** tboimah has quit (Remote host closed the connection) | 14:36 | |
*** fkoikoi has quit (Remote host closed the connection) | 21:52 |
Generated by irclog2html.py 2.17.3 by Marius Gedminas - find it at https://mg.pov.lt/irclog2html/!