data = [[1], [2, 3], [4, 5]]
output = [element for each_list in data
if len(each_list) == 2
for element in each_list
if element != 5]
print(output)
# Out: [2, 3, 4]
ZGF0YSA9IFtbMV0sIFsyLCAzXSwgWzQsIDVdXQpvdXRwdXQgPSBbZWxlbWVudCBmb3IgZWFjaF9saXN0IGluIGRhdGEKICAgICAgICAgICAgICAgIGlmIGxlbihlYWNoX2xpc3QpID09IDIKICAgICAgICAgICAgICAgIGZvciBlbGVtZW50IGluIGVhY2hfbGlzdAogICAgICAgICAgICAgICAgaWYgZWxlbWVudCAhPSA1XQpwcmludChvdXRwdXQpCiMgT3V0OiBbMiwgMywgNF0=