I've spent some time on this as an answer elsewhere, and did my best to optimize it. But looking at the hill of indents seems like this can be improved. I've tried to implement an
any() statement to replace the
break part, without any luck. Does anyone have any suggestions?
Groups = [[['NM1', 'OP', '1', 'SMITH', 'JOHN', 'PAUL', 'MR', 'JR'], ['ABC', '1L', '690553677'], ['DIR', '348', 'D8', '20200601'], ['DIR', '349', 'D8', '20200630']], [['NM1', 'OP', '1', 'IMA', 'MEAN', 'TURD', 'MR', 'SR'], ['ABC', '1L', '690545645'], ['ABC', '0F', '001938383',''], ['DIR', '348', 'D8', '20200601']]] def ids(a, b): l =  for group in Groups: for lst in group: if lst == a and lst == b: if lst == 'D8': l.append(lst) else: l.append(lst) break else: l.append(None) return l current_id = ids('ABC', '1L') prior_id = ids('ABC', '0F') start_date = ids('DIR', '348') end_date = ids('DIR', '349') print(current_id) print(prior_id) print(start_date) print(end_date)
['690553677', '690545645'] [None, '001938383'] ['20200601', '20200601'] ['20200630', None]
So basically, I have this
Groups list, in that list are 2 nested lists.
Assuming the output lists are
[x, y], the first nested list in
x, and the second is
You see my function has two parameters,
y are determined when their corresponding nested list has a list that has
a as the first index, and
b as the second index.
If the nested list doesn't have a list that meets that requirement, the
y will be
UPDATE: Is there any way to flatten the series of indents? At least a few?