Is there a more efficient way to return a list that contains a certain element from a list of lists?
For example:
lists = [['A', 'B', 'D', 'E', 'F', 'G', 'H'], ['C']]
If my input is C return the list ['C'] or if my input is D return the list = ['A', 'B', 'D', 'E', 'F', 'G', 'H']
What I've tried:
for lst in lists:
for n in range(len(lst)):
if element == lst[n]:
print(lst)
This is inefficient and I would like to know how to make it more efficient.
for item in lst:instead offor n in range(len(lst)):andlst[n]if element in lst, but otherwise no choice but to loop...