I have a list that can contain strings and integers, but I want to join all adjacent strings, only if there is no integer between those strings. For example :
list_a = [0, 0, "c", "a", "k", "e", 0, 0, "y", "o", "u", 0]
taken = []
for let in list_a:
if let == 0:
pass
else:
taken.append(let)
word = "".join(taken)
print(word)
>> cakeyou
I want to get either "cake" or "you" or both as two words. "Cakeyou" should not be an output because to get "cakeyou" the loop would move pass two zeros when it should stop the moment it meets any zero after reading some strings. Another important detail is that the words cake or you could be anywhere in the list, here I chose the index for simplicity (so slicing would not be a viable option)