This file contains 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 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 |
This file contains 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 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) |
This file contains 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 remove_duplicates(list): | |
newset = set() | |
for num in range(len(list)): | |
for item in list: | |
newset.add(item) | |
return newset |
This file contains 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
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) |
This file contains 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 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 |
This file contains 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 backwards(string): | |
num = 1 | |
while num < (len(string)+1): | |
print (string[-num], end="") | |
num += 1 |
This file contains 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 count(string, letter): | |
thecount = 0 | |
for item in string: | |
if item == letter: | |
thecount = thecount + 1 | |
print (thecount) |
This file contains 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 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' |
This file contains 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 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 |
This file contains 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
prefixes = 'JKLMNOPQ' | |
suffix = 'ack' | |
for letter in prefixes: | |
if letter == 'O' or letter == 'Q': | |
print (letter + 'u' + suffix) | |
else: | |
print (letter + suffix) |