I have this code:
with open("text2.txt", 'r') as file:
for cats in file:
if "blue" in cats:
print (cats)
the text2.txt file looks like this:
blue cat 3
blue cat 2
blue cat 5
red cat 2
green cat 2
blue cat 3
yellow cat 5
I want to get a list that looks like this:
["blue cat 3, blue cat 2, blue cat 5, blue cat 3"]
And the "make your list by hand" is not a option for me, I'm dealing with a big file, so this is not a solution for my problem:
mylist = ["blue cat 3, blue cat 2, blue cat 5, blue cat 3"]
blue catsblue catsblue catsbelow the rest. Do you want to include allblue catslines, or just the ones that appear right on top of each other.