Here is my code, I want to do a conditional concatenation, my issue is that at the end of the for loop I have all variables starting with \n. To remove it I need to strip out each variable. I think there should be some batter way to handle this. Any suggestions would be appreciated.
foo = bar = remaining = ''
for i in ['foo', 'foo', 'hello', 'foo', 'tr', 'foo', 'bar', 'foo', 'el']:
if 'foo' in i:
foo += '\n%s' % i
elif 'bar' in i:
bar += '\n%s' % i
else:
remaining += '\n%s' % i
foo = foo.strip()
bar = bar.strip()
remaining = remaining.strip()
\n? Your own code is what places it in the output variables. There are a couple of ways you could tidy up that string concatenation to skip the newlines.