I am new to Python and I am trying to filter out a string based on some criteria. I just want throw an error when there is not a 'c' after the second '/' or the string does not start with 'a'. Here is what I am doing -
if sample_data.split('/')[2] != 'c' or sample_data[:1] != 'a':
print('Unexpected data')
exit()
print('Further processing')
here is output based on the input I pass -
sample_data = 'a/b/c/d output - Further processing --> AS EXPECTED
sample_data = 'x/b/y/d output - Unexpected data --> AS EXPECTED
sample_data = 'a/b/y/d output - Unexpected data --> NOT AS EXPECTED
sample_data = 'x/b/c/d output - Unexpected data --> NOT AS EXPECTED
I guess I am missing something basic here.
ifstatement is actually executing correctly, per your description. The first failed example does not havecafter the second/. The second failed example does not start witha. Is this not your criteria? Like @UziGoozie said, you may be looking forandinstead ofor.