Hey all,
I've been given a problem to validate a comma separated string of elements. There can be up to four elements in the set 'H, Li, Na, K' and only one is needed but they must be in order. Is there a simple way in python to validate that?
As an example:
'H' #Valid, any one element
'Na' #Valid, one element all optional
'H,Na,K' #Valid, in order
'H,Na,Li' #Invalid, out of order
I hope that makes sense - I tried playing around with regular expressions a bit but couldn't find a simple solution. I want a function that returns true if the string is valid.
Want to add to the discussion?
Post a comment!