Name____________________ net-id _________ Name____________________ net-id _________ Name____________________ net-id _________
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): close(f)