IRC log of #jetrowebdev for Thursday, 2024-01-04

*** scooper has quit (Quit: Leaving)11:28
jelknerGood day, tboimah11:47
tboimahGood morning Jeff11:47
jelknerthanks for starting that email exchange yesterday11:48
jelknerwe need to continue to have discussions like that11:48
jelknerwe'll have a lot of them when i'm in monrovia next summer!11:48
jelknerdo you know if you all have any questions for me today?11:49
jelkneri have to run off copies of two quizzes for today11:49
jelknerso i need to get to the copy machine before it gets too busy11:49
jelkneri can stay for the planned 10 minutes11:49
tboimahi have one question for you Jeff11:49
jelknerbut no longer11:49
jelknergive it to me11:49
tboimahOkay the question is:11:50
tboimaht = [[3-i for i in range (3)] for j in range (3)]11:50
tboimahs = 011:50
tboimahfor i in range(3):11:50
tboimah    s += t [i][i]11:50
tboimahprint(s)11:50
tboimahThat is a code11:50
tboimahthat code will give 611:50
jelknerso you have a nested list comprehension11:51
tboimahas the answer i have explain in my own way i get the same 6 but i will11:51
jelknerto evaluate it, you need to work from the inside out11:51
tboimahalso need you to explain11:51
jelknerfirst, you need to evaluate [3-i for in in range(3)]11:52
jelknerrange(3) returns an iterator that will produce 0, 1, and 211:52
jelknerso 3 - i for each of those will produce...11:52
jelkner[3, 2, 1]11:52
jelknerright?11:52
tboimahyeah11:53
jelknertry it in the REPL11:53
tboimahi already try it 11:53
jelknerok, next, the for j in range(3) just repeats that 3 times11:53
tboimahi just need you to explain11:53
jelknerso you get 3 copies11:53
jelknerit will look like:11:53
jelkner[3, 2, 1], [3, 2, 1], [3, 2, 1]]11:54
jelkneroops, i'm missing an [11:54
jelknerin the beginning11:54
jelknerit is a nested list11:54
jelkner3 copies of the same [3, 2, 1] list11:54
jelknermake sense?11:54
tboimahsure 11:54
jelknergreat11:55
tboimahso the answer will be six11:55
jelknerso no, we evaluate the for loop11:55
tboimahbecause11:55
jelknergo ahead11:55
tboimah3 - 0 is 311:55
tboimahand 3 -1 is 211:55
jelknerhmmm11:56
tboimah3- 2 is 111:56
jelknernot exactly11:56
jelknerwhen you see nested lists like this11:56
tboimahthen explain more11:56
jelknerone way to think of it is a a matrix11:56
jelknerare you familiar with matrices from math?11:56
tboimahyeah 11:56
jelknerinstead of [[3, 2, 1], [3, 2, 1], [3, 2, 1]]11:57
jelknerthink of it like this:11:57
jelkner[[3, 2, 1],11:57
jelkner  [3, 2, 1],11:57
jelkner  [3, 2, 1]]11:57
jelkneroops, i wanted them to line up11:57
jelkneranyway, we have rows and columns11:57
tboimahyeah three row and three colums11:58
jelknerif we name this matrix m11:58
jelknerwhat value is at m[0][0] ?11:58
tboimah311:58
jelkneryes!11:58
jelknerand m[1][1] ?11:58
tboimahwill be 211:58
jelknerexactly!11:58
jelknerso this for loop is adding the values along the main diagonal11:59
jelkners = 3 + 2 + 111:59
jelknersince m[2][2] is 111:59
jelknertake a look at kevin's email12:00
jelknerwhat you should do now12:00
jelkneris make some changes to this code so that it changes the matrix produced12:00
jelknerthen see if you can predict what will happen12:00
jelknert = [[3+i for i in range (3)] for j in range (3)]12:01
jelknerfor example12:01
jelknerso make it a 4 x 4 matrix12:01
jelknert = [[4-i for i in range (4)] for j in range (4)]12:01
jelknerthings like that12:01
jelkner"play" with the code until it becomes yours12:02
jelknernice question12:02
jelkneri have to go12:02
jelknerbut i'll be back tomorrow12:02
tboimahsure thanks12:02
jelknerkevin meets with you tomorrow, yes?12:03
tboimah yes12:03
jelknerhe is a great tutor12:03
jelknerand you'll have 2 hours with him12:03
jelknerokie dokie12:03
jelknertalk to you tomorrow...12:03
tboimahokay12:03
tboimahhave a nice day12:03
jelkneryou too!12:04
jelknerACTION 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/!