Name____________________ net-id _________ Name____________________ net-id _________ Name____________________ net-id _________
list_a
and list_b
are lists of strings, for example (but
don't answer assuming these lists in particular -- however, you can
assuming the lists don't contain duplicates):
list_a = ["brown", "aqua", "maroon", "orange", "blue", "red"] list_b = ["black", "blue", "magenta", "red"]
list_a
or in list_b
, but
with no duplicates (more than one is possible):
[x for x in list_a if x in list_b]
list(set(list_a) | set(list_b))
list_a
and in list_b
, but
with no duplicates (more than one is possible):
[x for x in list_a if x in list_b]
list(set(list_a) & set(list_b))
list_a
but not in list_b
--
which of the following do this (more than one is possible)?
[x for x in list_a if not x in list_b]
list(set(list_a) - set(list_b))
[e for e in list_a if list_b.count(e) < 2]
s^t
for sets
s
and t
(more than one is possible)?
(s-t) | (t-s)
(s|t) - (s&t)
(s|t|(s&t))