You're using backslashes too much. You gotta use only as many as in string0. So "just" '(\''+'\',\''.join(list)+'\')'. And if you switch the outer quotes to ", then you don't need escapes with ' at all - "('" + "','".join(list) + "')"
How to do it in a nicer way:
Let's do it the other way around, we have your string0:
string0 = 'case when \"LETTER\" in (\'a\',\'b\') then \"LETTER\" else \'other letter\' end'
Let's just get everything you wanted out and add it as a whole formatting:
ab_string = '(\'a\',\'b\')'
string0 = f'case when \"LETTER\" in {ab_string} then \"LETTER\" else \'other letter\' end'
Now, let's take a look at ab_string: '(\'a\',\'b\')'. If we change the quotes to double, we will see those are just "('a','b')" - the escapes were only there to avoid collision with the outer quotes of string0.
So we can just do the thing you had:
ab_list = ['a','b']
ab_string = "('" + "','".join(ab_list) + "')"
string0 = 'case when \"LETTER\" in ' + string + ' then \"LETTER\" else \'other letter\' end'
Now, a hack: Do you know how printing a list itself looks like? ['a', 'b'], right? So we can even get a hacky way of just replacing the outer [] - cut the edges off using indexes, add ()
ab_list = ['a', 'b']
ab_string = f'({str(ab_list)[1:-1]})'
string0 = f'case when \"LETTER\" in {ab_string} then \"LETTER\" else \'other letter\' end'
f'({",".join(map(repr, lst))})'=>('a','b').