Skip to content

Instantly share code, notes, and snippets.

View shamikalashawn's full-sized avatar
💭
Polishing my latest app!

Shamika La Shawn shamikalashawn

💭
Polishing my latest app!
View GitHub Profile
@shamikalashawn
shamikalashawn / Invert Dictionary
Created February 1, 2017 03:29
Take a dictionary, with its keys and values, and I can make the values keys and turn the keys into values!
def invert_dict(a_dict):
idict = {}
keylist = []
valuelist = []
for key in a_dict:
keylist.append(key)
for value in a_dict.values():
valuelist.append(value)
idict = dict(zip(valuelist, keylist))
return idict
@shamikalashawn
shamikalashawn / Common Values
Created February 2, 2017 23:10
When provided with two tuples, a set is returned with the common elements found in each tuple.
def common_values(tuple1, tuple2):
if type(tuple1) != tuple or type(tuple2) != tuple:
return "Params not of type 'tuple'"
else:
set1 = set(tuple1)
set2 = set(tuple2)
return set1.union(set2)
@shamikalashawn
shamikalashawn / Remove Duplicates
Created February 2, 2017 23:13
Given a list, a set is returned with all duplicates removed.
def remove_duplicates(list):
newset = set()
for num in range(len(list)):
for item in list:
newset.add(item)
return newset
@shamikalashawn
shamikalashawn / Birthday Database
Created February 2, 2017 23:14
A database of birthdays can be queried or added to.
birthdays = {'Alice': 'Apr 1', 'Bob': 'Dec 12', 'Carol': 'Mar 4'}
while True:
print('Enter a name: (blank to quit)')
name = input()
if name == '':
break
if name in birthdays:
print(birthdays[name] + ' is the birthday of ' + name)
@shamikalashawn
shamikalashawn / Advanced Nested Pyramid
Created February 6, 2017 22:36
A character is turned into a pyramid!
def advanced_nested_pyramid(start = 1, last = 5, char = '*'):
pyramid = ''
pylength = range(start, last+1)
for num in range(1):
for pynum in pylength:
pyramid = pyramid + char * pynum + '\n'
return pyramid
@shamikalashawn
shamikalashawn / Backwards
Created February 6, 2017 22:38
The string provided is returned reversed.
def backwards(string):
num = 1
while num < (len(string)+1):
print (string[-num], end="")
num += 1
@shamikalashawn
shamikalashawn / Count
Created February 6, 2017 22:41
Given a string and a letter, a number of times that letter appears in the string is returned.
def count(string, letter):
thecount = 0
for item in string:
if item == letter:
thecount = thecount + 1
print (thecount)
@shamikalashawn
shamikalashawn / Create Open Box
Created February 6, 2017 22:43
A character is turned into a box with the inside missing.
def create_open_box(height, width, character):
box = ''
if height in range(1,3) or width in range(1,3):
for row in range(height):
box = box + (character * width) + '\n'
print('regular open box')
else:
for row in range(height):
if row == 0 or row == height-1:
box = box + (character * width) + '\n'
@shamikalashawn
shamikalashawn / Create Box
Created February 6, 2017 22:45
A character turns into a box with the dimensions of the height and width provided.
def create_box(height, width, character):
if height >= 1 and width >=1:
box = ''
for row in range(height):
box = box + (character * width) + '\n'
print (box)
return box
@shamikalashawn
shamikalashawn / Ducklings
Created February 6, 2017 22:48
The letters from "J" to "Q" are turned into onomatopoeias with the suffix "ack".
prefixes = 'JKLMNOPQ'
suffix = 'ack'
for letter in prefixes:
if letter == 'O' or letter == 'Q':
print (letter + 'u' + suffix)
else:
print (letter + suffix)