Skip to main content

Notes - Sunday 01/17/21

TIL

Today I'm working on some practice problems. I'm going to take some notes on what I learned while I go through these problems. Unfortunately the solutions include things we've never gone over in the lectures. Reference this link for the questions and this link for the answers.

 

  • Remember to read over the notes carefully and don't rush to solve a problem for no reason.

 

  • If you're using string.split() function, remember that the resulting list will have index positions based on the entire string. Then you can breakdown the string further. For example:

    my_list_of_words = some_words.split() = ['Hello World'] (this isn't perfect syntax, just go with it) yields ['Hello','World']

    This means that my_list_of_words[0] yields 'Hello' and my_list_of_words[1] yields 'World'

    Then you can break this down further to get just individual letters. For example my_list_of_words[0][0] yields 'H' and my_list_of_words[1][0] yields 'W'

 

  • .join() method: So you can use this method to combine or join strings. The basic syntax is:

    "stuff_between_ur_words".join(ur_variable)

    So let's look at a practice problem to explain it:

    MASTER YODA: Given a sentence, return a sentence with the words reversed
    
    master_yoda('I am home') --> 'home am I'
    master_yoda('We are ready') --> 'ready are We'
    

CBAPractice01.png

 

TIL Continued...

  • You can find the absolute value of a number by using abs. The syntax would be abs(ur_number)

 

  • Assignment operators exist. Here's a list of them. Things like += and = can help. I didn't know they existed.

 

  • Remember that you can get the sum of numbers using sum(ur_numbers)

 

  • When you have a loop, order the loop matters. It will literally execute the logic line by line so if you're not setting up the loop in the order you want it to check in, it won't output what you want.