I have the following function in Python:
def _extract_grp_entitlements(self,saml_authentication_attributes,groups):
result = []
input_length = len(saml_authentication_attributes[groups])
if input_length == 0:
log.error(self.empty_entitlements_message)
raise RuntimeError(self.empty_entitlements_message)
if input_length == 1:
result = [t.strip() for t in saml_authentication_attributes[groups][0].split(',')]
elif input_length:
result = saml_authentication_attributes[groups]
return result
Are there any benefits/drawbacks (aside from the logical control flow) - speed, memory, etc. - for replacing the elif
there with the else
clause?
Would this be preferable:
def _extract_grp_entitlements(self,saml_authentication_attributes,groups):
input_length = len(saml_authentication_attributes[groups])
if input_length == 0:
log.error(self.empty_entitlements_message)
raise RuntimeError(self.empty_entitlements_message)
return [t.strip() for t in saml_authentication_attributes[groups][0].split(',')] \
if len(saml_authentication_attributes[groups]) == 1\
else saml_authentication_attributes[groups]