Skip to content

Instantly share code, notes, and snippets.

@reeddunkle
reeddunkle / leo_int_list_comprehension
Created May 30, 2016 23:01
convert r, c to int()
#Leo, I found a better way. Look where I moved the int() call to:
r, c = [int(c) for c in user_input if c.isdigit()][:2]
# r = int(r)
# c = int(c)
import os
import time
from random import randint
os.system('cls' if os.name == 'nt' else 'clear')
DOWN = "Down"
RIGHT = "Right"
DESTINATION = "Destination!"
EMPTY_CHAR = "[ ]"
OBSTACLE_CHAR = "[X]"
@reeddunkle
reeddunkle / Exercise9-2.py
Created May 5, 2016 17:42
List Comprehension Exercise
'''
This is hacky and ugly. It only works because both
lists are the same size, etc. etc.
Upon researching this, it seems that this is an example
when map() is actually way better and preferable.
There's also a function called zip() which does this,
but I haven't learned zip() yet.
@reeddunkle
reeddunkle / Exercise8-2.py
Created May 5, 2016 16:49
List Comprehension Map
FILES = ["picture1", "georgi_paws_everywhere", "custom_wreath"]
results = ["{}.jpg".format(file) for file in FILES]
print results
@reeddunkle
reeddunkle / Exercise9.py
Last active May 5, 2016 16:50
Custom Map Exercise
NUMBERS = range(4)
NAMES = ['Rebecca', 'Georgi', 'Reed', 'Thom Yorke']
def my_map(function, iterable):
output = []
for element in iterable:
result = function(element)
@reeddunkle
reeddunkle / Exercise8.py
Last active May 5, 2016 16:30
Custom Map Exercise
FILES = ["picture1", "georgi_paws_everywhere", "custom_wreath"]
def my_map(function, iterable):
output = []
for element in iterable:
result = function(element)
output.append(result)
@reeddunkle
reeddunkle / Exercise7.py
Last active May 4, 2016 20:07
Custom Map Method
def my_map(function, iterable):
output = []
for element in iterable:
result = function(element)
output.append(result)
return output
@reeddunkle
reeddunkle / Exercise6.py
Created May 2, 2016 18:59
Custom Filter Exercise
def my_filter(function, iterable):
output = []
for item in iterable:
if function(item):
output.append(item)
return output
@reeddunkle
reeddunkle / tuples.sh
Last active May 4, 2016 19:10
Tuples Example
>>> tuple = ('fashion', 'nugget')
>>> tuple[0]
'fashion'
>>> tuple[1]
'nugget'
@reeddunkle
reeddunkle / startswith.sh
Last active May 4, 2016 19:11
Python startswith() method
>>> string = "Reed Dunkle"
>>> string.startswith('Reed D')
True
>>> string.startswith('Re')
True
>>> string.startswith('Reed W')
False
>>>