The way to write for loop in a single line, mostly used in Data Science Project, You can use this way, as we have six labeled fake news LIAR:
Labels: ['barely-true' 'false' 'half-true' 'mostly-true' 'pants-fire' 'true'], to represent this as a binary labels:
We use the following way:
labels = [ 1 if lab=='false' or lab=='pants-fire' or lab=='barely_true' else 0 for lab in df.is_fake]
Another way, the same if-else condition for loop:
labels = [ 1 if lab=='false' else 1 if lab=='pants-fire' else 1 if lab=='barely_true' else 0 if lab == 'true' else 0 if lab == 'half-true' else 0 for lab in df.is_rumor]
Hope to help many of you, who want to do the same way in many problem-solving.