Last active
March 17, 2017 17:48
-
-
Save xie/c3c101bd67604ac9f4a20f5386e83c3b to your computer and use it in GitHub Desktop.
midterm2 - hughxie
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
''' | |
Dropping this here if anyone finds it useful. | |
PLS nobody talk about efficiency lol | |
''' | |
####Q1#### | |
def both(list1, list2): | |
list_3 = list(set(list1 + list2)) | |
list_4 = [] | |
print(list_3) | |
for i in list_3: | |
if (i in list1) and (i in list2): | |
list_4.append(i) | |
return list_4 | |
####Q2#### | |
def strcount(str1,str2): | |
counter = str1.count(str2) | |
return counter | |
####Q3#### | |
def multiply(list1,valuex): | |
arguments = dict() | |
for i in list1: | |
arguments[i] = arguments.get(i,0)+1 | |
newlist = [] | |
for x in arguments.keys(): | |
for i in range((int(arguments[x]))*valuex): | |
newlist.append(x) | |
return newlist | |
####Q4#### | |
def grades(): | |
while True: | |
sid = input('quit to exit program. Enter student number: ') | |
if sid == 'quit': | |
break | |
sgrade = int(input('Enter grade for '+sid+' : ')) | |
if sid in s: | |
s[sid].append(sgrade) | |
else: | |
s[sid] = [] | |
s[sid].append(sgrade) | |
print(s) | |
print(len(s.keys())) | |
n = dict() | |
for key,i in s.items(): | |
total = 0 | |
average = 0 | |
for x in i: | |
total += x | |
average = total/len(i) | |
n[key] = [] | |
n[key].append(average) | |
return n | |
####Q5#### | |
def remove(str1,removestr): | |
strlist = [] | |
strlist = str1.split(removestr) | |
while True: | |
str3 = '' | |
for i in strlist: | |
str3 += i | |
if removestr in str3: | |
strlist = str3.split(removestr) | |
else: | |
break | |
return str3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment