Name____________________ net-id _________ Name____________________ net-id _________ Name____________________ net-id _________
if
w.startswith("<") in the function
expand below:
w may require
expansion because it has tags in it, so the rule
is passed to expand in case it's more than a simple word.
w starts with a < symbol we
know a choice should be made to replace it, but the line
assigning to sent could be replaced with:
rules is a dictionary, accessing
the dictionary generates a random replacement for the key w
and that replacement also starts with a < symbol.
sent.strip() is
returned rather than simply sent?
sent in
the for-loop.
sent, not
just leading and trailing white-space.
colors in the function
create_content?
These questions refer to Sierpinsk1.py which generates a Sierpinski gasket.
p1, p2 and
p3 to the function sierpinski:
sierpinski
will eventually terminate, i.e., stop generating recursive
calls?
level decreases in each recursive call, eventually
reaching 0 when no calls are made.
chaos?
These questions refer to Koch.py which generates a Koch Snowflake.
draw?
draw
if the value of parameter iters is 1, what will the length
of string flake be after the first for-loop?
iters is 4 what will the length
of flake be?
a and b. More than one can be correct.
list(set(a)&set(b))
[x for x in a if x in b]
[x for x in set(a) if x in set(b)]
x = [1,2,3] y = [5,6,7]
[(a,y[i]) for i,a in enumerate(x)]
[(1,5), (2,6), (3,7)]
[(5,1), (6,2), (7,3)]
[(0,5), (1,6), (2,7)]
[(a,b) for a in x for b in y]?
[(1,5), (2,6), (3,7)]
[(1,5),(1,6),(1,7),(2,5),(2,6),(2,7),(3,5),(3,6),(3,7)]
[(1,7), (2,6), (3,5)]
[x for x in range(100) if x % 3 == 0]
represents the list [0,3,6,...,96,99], i.e., multiples of
three less than 100. Write a list comprehension for multiples of
seven between 500 and 600 (inclusive).
[0,1,4,9,16,25,...,441,484]
Duke Chronicle:svp9,tlm,fro72 Student Government:tlm,ola,ezp9 Ski Club: fro72, frp9, tlm,ghtEach group/club is the first part of a line, followed by a colon, followed by the net-ids of those in the group/club. Write a function that has a filename as a parameter and which returns a dictionary in which keys are net-ids/strings and the associated value is a list of organizations to which the person with the net-id belongs to. For example in the file above:
tlm : ["Duke Chronicle", "Student Government", "Ski Club"]Complete the function below:
def groups(filename):
"""
filename is name of a file in proper format
returns dictionary with net-id as key and value
a list of groups/organizations
"""
f = open(filename):
#code here
close(f)