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 datetime | |
import time | |
while True: | |
with open('filename.txt', 'w+') as output: | |
now = datetime.datetime.now().time().strftime('%I:%M:%S') | |
output.write(now) | |
time.sleep(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
# Assignments | |
### *mutability | |
What's the difference between a mutable and an immutable type? Why should I use one or the other? Write the following two functions, both receiving a list of elements and a new elemnt to append at the end. The first one should be a mutable version and the second an immutable version. | |
Example mutable: | |
l = [1, 2, 3] | |
mutable_append(l, '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
class Chair(object): | |
"""Individual chair within the aircraft""" | |
def __init__(self, price=25): | |
self.price = price | |
self.occupied = False | |
def purchase(self): | |
self.occupied = True |
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 traceback | |
import datetime | |
import praw | |
import time | |
from PasswordManager import pswds | |
r = praw.Reddit('Responds to forgetful OPs in /r/DrunkOrAKid' | |
'by /u/echocage') | |
r.login(username='BecauseOPForgot', password=pswds['BecauseOPForgot']) |
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 java.io.BufferedReader; | |
import java.io.FileNotFoundException; | |
import java.io.FileReader; | |
import java.io.IOException; | |
import java.util.ArrayList; | |
public class parser { | |
public static Integer[] getId(String nameGoal) { | |
ArrayList<Integer> ids = new ArrayList<Integer>(); | |
try { |
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 os | |
import argparse | |
import sys | |
from sh import rsync | |
parser = argparse.ArgumentParser() | |
parser.add_argument("BACKUPDIR", help="Specify the directory to backup.") | |
parser.add_argument("DESTINATIONDIR", help="Specify the directory where the backup is stored.") | |
args = parser.parse_args() |
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 Animal(object): | |
def __init__(self, name, height, weight, sound): | |
self.name = name | |
self.sound = sound | |
self.weight = weight | |
self.height = height | |
def __str__(self): | |
return "{} is {} cm height {} lbs weight and says {}".format(self.name, self.height, self.weight, | |
self.sound) |
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
from collections import Counter | |
import praw | |
import time | |
female_indicators = ["I", "me", "my", "mine", "myself", "you", "your", "yours", "yourself", "she", "her", "hers", | |
"herself"] | |
male_indicators = ["we", "us", "they", "them", "he", "him", "his", "himself"] | |
def calculate_gender(comment_text): |
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
verses = ["a Partridge in a Pear Tree", "Two Turtle Doves", "Three French Hens", "Four Calling Birds", | |
"Five Gold Rings", "Six Geese-a-Laying", "Seven Swans-a-Swimming", "Eight Maids-a-Milking", | |
"Nine Ladies Dancing", "Ten Lords-a-Leaping", "Eleven Pipers Piping", "Twelve Drummers Drumming"] | |
for index, verse in enumerate(verses): | |
day = index + 1 | |
previous_verses = verses[:day] # This cuts out and returns all elements from 0, to day from the list of verses | |
ordered_verses = reversed(previous_verses) | |
# Shockingly, this ^ reverses the list, so we have a list of elements starting from the newest item to the oldest | |
chorus = "On the {} day of Christmas my true love sent to me,".format(day) |
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
verses = ["a Partridge in a Pear Tree", "Two Turtle Doves", "Three French Hens", "Four Calling Birds", | |
"Five Gold Rings", "Six Geese-a-Laying", "Seven Swans-a-Swimming", "Eight Maids-a-Milking", | |
"Nine Ladies Dancing", "Ten Lords-a-Leaping", "Eleven Pipers Piping", "Twelve Drummers Drumming"] | |
days = {index - 1: ', '.join(reversed(verses[:index - 1])) for index, verse in enumerate(verses)} | |
def get_day(day):return "On the {} day of Christmas my true love sent to me,".format(day) + days[day] | |
def get_presents(start, end=None):return sum(range(start)) if not end else sum(range(start, end + 1)) | |
print(get_presents(11, 12)) |