In my code I have the following:
if all(requiredField in submittedFields for requiredField in requiredFields):
# all required fields in submittedFields exist
else:
# error handling
The goal is to check if a list of strings in requiredFields
are all present in submittedFields
This works fine when requiredFields
is a list of strings with length > 1. But, when you have something like
requiredFields = ('single element')
Then the for loop iterates over each character instead of the string itself.
So my question is, is there a more pythonic means of handling this other than
try:
requiredFields.sort()
# requiredFields is a list of strings
except AttributeError:
# requiredFields is a string list whose length == 1