This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| lambda x: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| x = [1, 2, 3, 4, 5] | |
| def square(num): | |
| return num*num | |
| print(list(map(square, x))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| map(function, iterable) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for c in Counter(3, 8): | |
| print(c) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Counter: | |
| def __init__(self, low, high): | |
| # set class attributes inside the magic method __init__ | |
| # for "inistalise" | |
| self.current = low | |
| self.high = high | |
| def __iter__(self): | |
| # first magic method to make this object iterable | |
| return self |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def factorial_recursive(n): | |
| # Base case: 1! = 1 | |
| if n == 1: | |
| return 1 | |
| # Recursive case: n! = n * (n-1)! | |
| else: | |
| return n * factorial_recursive(n-1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| a = 3 | |
| def some_func(): | |
| global a | |
| a = 5 | |
| some_func() | |
| print(a) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # based off of this code https://gist.github.com/nandajavarma/a3a6b62f34e74ec4c31674934327bbd3 | |
| # Brandon Skerritt | |
| # https://skerritt.tech | |
| def binary_search(the_array, item, start, end): | |
| if start == end: | |
| if the_array[start] > item: | |
| return start | |
| else: | |
| return start + 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Deploy bot for Python | |
| # TODO | |
| # check all links on page for 404 | |
| import check_link | |
| from bs4 import BeautifulSoup | |
| import urllib.request | |
| from multiprocessing import Process | |
| # creates a global check_link object |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import collections | |
| Card = collections.namedtuple('Card', ['rank', 'suit']) | |
| class FrenchDeck: | |
| ranks = [str(n) for n in range(2, 11)] + list(JQKA) | |
| suits = "spades diamonds clubs hearts".split() | |
| def __init__(self): | |
| self.cards=[Card(rank, suit) for suit in self.suits |