We learned about recursions in class this week and it took a while for my brain to understand the code.
Take the lab, for example.
Tracing the code was doable for me, but it took more and more brainpower as more and more sublists were added into lists.
Writing the code for length(L) was very confusing.
I started out with
if isinstance(L, list):
return [length(x) for x in L]
else:
return 0
My if statement started out by replacing each element in L, whether it was a list or a sublist, to 0's.
Then I had difficulty going into each sublist to find the length of each list and return the maximum length.
I knew I had to somehow incorporate max() and len() into the code...
When the list has one sublist inside the list, I'm comparing to the length of the outside list, and the length of the list inside.
But what if there was another sublist inside the sublist?
Then I would have to take the maximum of the first sublist and compare it to the length of the sublist inside the sublist.
Which means the if statement should be:
if isinstance(L, list):
return max(len(L), max([length(x) for x in L]))
Saturday, January 31, 2015
Thursday, January 22, 2015
Why Geeks Should Write
Everyone should write!
In between our busy lives, we should take a breath, slow down, and think.
Why am I doing this? Why am I programming? Why computer science?
It forces us to go through the millions of thoughts racing through our minds.
If you're having trouble, writing it out helps you think about it more and maybe eventually solving the problem.
For example, for the past few weeks, I've noticed that CSC148 is quite more advanced than the CSC108 course I took last semester.
In CSC108, we were given the functions and we just had to write the code for it.
In CSC148, we're expected to make our own functions based on information given to us about what we want the program to do.
It's different and it's hard for me. I'm still not very sure what functions I need to make and what variables need to go along with it.
The labs give me a satisfied feeling after I complete them, but the quizzes are telling a different story.
Week 2's quiz, for example, was confusing to me.
I think I was supposed to return a sentence in a subclass with .format, where I have to insert certain things from the information given from the superclass.
But of course, I realized that after I handed in the quiz as time had already run out.
I was trying to access the list of information that was created in the subclass, but we were told it was a dictionary and not a tuple so I didn't know how to access the information at specific indexes?
Maybe it was a dictionary with a tuple as the value. So that I would be able to index the tuple and format it with the sentence.
That makes sense.
Why couldn't I have made sense of it during the quiz?
I panicked and didn't know what to do.
I should stop panicking.
And be more confident.
Today, after handing in the quiz, I felt sad. Now I am writing about it, so now I feel even more sad that I didn't think about this solution while I was writing the quiz.
I suppose I'm supposed to feel better about it since I now know what I did wrong, but not really because I'm upset that I wasn't able to demonstrate my knowledge on the quiz.
I understand what's going on in class.
Maybe I should do more practice.
Maybe my knowledge will eventually be reflected by my grades.
(Hopefully!)
In between our busy lives, we should take a breath, slow down, and think.
Why am I doing this? Why am I programming? Why computer science?
It forces us to go through the millions of thoughts racing through our minds.
If you're having trouble, writing it out helps you think about it more and maybe eventually solving the problem.
For example, for the past few weeks, I've noticed that CSC148 is quite more advanced than the CSC108 course I took last semester.
In CSC108, we were given the functions and we just had to write the code for it.
In CSC148, we're expected to make our own functions based on information given to us about what we want the program to do.
It's different and it's hard for me. I'm still not very sure what functions I need to make and what variables need to go along with it.
The labs give me a satisfied feeling after I complete them, but the quizzes are telling a different story.
Week 2's quiz, for example, was confusing to me.
I think I was supposed to return a sentence in a subclass with .format, where I have to insert certain things from the information given from the superclass.
But of course, I realized that after I handed in the quiz as time had already run out.
I was trying to access the list of information that was created in the subclass, but we were told it was a dictionary and not a tuple so I didn't know how to access the information at specific indexes?
Maybe it was a dictionary with a tuple as the value. So that I would be able to index the tuple and format it with the sentence.
That makes sense.
Why couldn't I have made sense of it during the quiz?
I panicked and didn't know what to do.
I should stop panicking.
And be more confident.
Today, after handing in the quiz, I felt sad. Now I am writing about it, so now I feel even more sad that I didn't think about this solution while I was writing the quiz.
I suppose I'm supposed to feel better about it since I now know what I did wrong, but not really because I'm upset that I wasn't able to demonstrate my knowledge on the quiz.
I understand what's going on in class.
Maybe I should do more practice.
Maybe my knowledge will eventually be reflected by my grades.
(Hopefully!)
Subscribe to:
Posts (Atom)