I have a set of lists that look like this:
conditions = [
["condition1", ["sample1", "sample2", "sample3"]],
["condition2", ["sample4", "sample5", "sample6"],
...]
how can I do the following things efficiently and elegantly in Python?
Find all the elements in a certain condition?
e.g. get all the samples in condition2. Right now I can do:
for cond in conditions:
cond_name, samples = cond
if cond_name == requested_cond:
return samples
but that's clunky.
Find the ordered union of a list of conditions? E.g. ordered_union(["condition1", "condition2"], conditions) should return:
["sample1", "sample2", "sample3", "sample4", "sample5", "sample6"]
How can I do this efficiently in Python? There are probably clever one liners?