CMU 15-112 Spring 2016 Quiz 6 Practice: Code Tracing (1 of 2)
(Due never)
- This is part of quiz6-practice.
- Quiz6 code tracing will be nearly identical to these.
# Code Tracing #1 of 2
import string
def keyFn(val): return (ord(val) - ord('a'))%5
def ct1(st):
(result, i) = ("", 1)
for c in sorted(set(st) - set(st.upper()), key=keyFn):
(result, i) = (result + i*c, i+1)
return (result, set(result))
print(ct1("bCDfCBe"))
# Code Tracing #2 of 2
def ct2():
(result, d) = (list(), dict())
for x in range(1,20,3):
d[x%4] = x
for key in sorted(d.keys()):
result.append((key, d[key]))
return result
print(ct2())