I have a list:
chain_views = [u'x|frequency|x:y|||cbase',
u'x|frequency|x:y||weights_UK18|cbase',
u'x|frequency||y|weights_UK18|c%']
I want to check the condition below against the list above
if el.startswith('x|frequency|') and el.split('|')[4]!='' and el.split('|')[3]=='y':
How can I convert the condition above in regex?
Right now I am checking this in a loop and I think regex would be a better option maybe?
for el in chain.views:
if el.startswith('x|frequency|') and el.split('|')[4]!='' and el.split('|')[3]=='y':
weighted_views = True
break
else:
weighted_views = False
return weighted_views
weighted_viewsresult of the last list element right now.continuewithbreak? Continue just does the next iteration, which it would do anyway. Also you could avoid callingel.split('|')twice. I know it's only example code, but still worth noting.