Binary Search Algorithm

No BS: It is important to try and implement known ‘easy’ algorithms as it provides practice on working towards trickier algorithms, as well as translating human instructions into a usable program. With BS: Working through Exercise 20 of practicepython.org, you are tasked to implement the Binary Search Algorithm for a sorted list of numerical integers, […]

Read more "Binary Search Algorithm"

Basic Exceptions

No BS: using a ‘while True’ loop and a ‘continue’ line in an exception is good because it gives the user another go at an input (if that’s what it was used for) without having to go through the whole program again.   With BS: So I just put together a quick program to check […]

Read more "Basic Exceptions"

re.findall()

No BS: re.findall(pattern, string) is a powerful tool that will find all matches of a particular pattern in a string. This could be used to produce a list of email addresses, IP addresses, post codes. An example would be s = ‘alice.goodall@google.com lorem ipsum neil.blompkamp@AOL.com adipiscing elit. Vestibulum jennifer@yahoo-net.com’ emails = re.findall(r'[\w_.-]+@[\w_.-]+’,s)   With BS: […]

Read more "re.findall()"

Word/Count Dict (Part 2)

No BS: Previous code didn’t strip out punctuation and left us with weird duplicates of words. For example, “the”, “the–“, and “(the” would all be considered separate words. I added a piece of code to strip out the punctuation which was: out = s.translate(str.maketrans(”, ”, string.punctuation)) I then sorted the words based on the output […]

Read more "Word/Count Dict (Part 2)"