Skip to content

Instantly share code, notes, and snippets.

import random
f = open("enable1.txt")
words = [x.strip().upper() for x in f.readlines()]
def CreateWords(difficulty=1):
"""Take the difficulty number and a list of words, return
a list of words accordingly"""
newwords = []
i = 0
import time
import sys
import praw
# ==========================================
# ===============Configuration==============
user = 'dogetipbot'
# ==========================================
@Echocage
Echocage / ResponseBot.py
Last active August 29, 2015 14:04
Reddit response bot for m_eq_errmg
import random
import time
import sys
import praw
# ==========================================
# ===============Configuration==============
user_to_reply_to = 'echocage'
messages = ['examplecomment1', "Example Comment 2"]
username = ""
data = r"""File Name : File1.txt
Directory : Path\to\File1.txt
Created : 2012:04:15 10:15:32
Accessed : 2012:04:18 13:28:18"""
items = []
for line in data.split('\n'):
type = line.split(':')[0].strip()
rest = ':'.join(map(lambda x: x.strip(), line.split(':')[1:]))
if type == 'File Name':
items.append({type: rest})
whitelisted_users = map(lambda x: x.strip('\n'), list(open('users')))
whitelisted_domains = map(lambda x: x.strip('\n'), list(open('domains')))
import praw
import time
import traceback
# ==========================================
# ===============Configuration==============
username = ""
import random
import urllib2
stages = [["O"], ["O", "|"], [" O", "/|"], [" O", "/|\\"], [" O", " /|\\", " /"], [" O", "/|\\", "/ \\"]]
words = urllib2.urlopen('http://pastebin.com/raw.php?i=1nCnmv2y').readlines()
words = map(lambda x: x.strip(), words)
words.sort(key=lambda x: len(x))
calchar = ("o", "i", "z", "e", "h", "s", "g", "l", "b", "g")
wordlist = []
with open("dictionary.txt") as f:
with open("newdict.txt", 'w') as output_file:
for line in f:
if all(c in calchar for c in line):
output_file.write(line)
@Echocage
Echocage / primes.py
Last active August 29, 2015 14:06
Primes "dummy exercise"
def find_next_prime(n):
while True:
n += 1
prime = isPrime(n)
if prime:
return n
def isPrime(n):
for item in xrange(2, n):
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)
# 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')