fork download
  1. codes = ['XA1', 'CZZ', 'BT9', 'WFF']
  2. strs = ['XA1', 'XA1;CZZ', 'XA1;BT9;WFF;', 'XA1;XA1;', 'XA1;something']
  3. for s in strs:
  4. chunks = s.strip(';').split(';')
  5. if set(chunks).issubset(codes) and len(chunks) == len(set(chunks)):
  6. print("{}: Valid!".format(s))
  7. else:
  8. print("{}: Invalid!".format(s))
Success #stdin #stdout 0.01s 27712KB
stdin
Standard input is empty
stdout
XA1: Valid!
XA1;CZZ: Valid!
XA1;BT9;WFF;: Valid!
XA1;XA1;: Invalid!
XA1;something: Invalid!